in reply to Re^6: [OT] LLP64 .v. LP64 portability
in thread [OT] LLP64 .v. LP64 portability

Seems to be perfectly defined for this purpose.

STRLEN is used for variables whose value will passed to the last argument of memcpy and for those that will receive the result of strlen. I don't see why it would be more suitable to use a different type than the actual type the functions use.

The problem is, as you pointed out above, size_t, (actually defined as what sizeof() returns), is an unsigned type, and therefore cannot handle negative indexing.

It does not need to handle negative indexing. The position and length are normalised before being stored into STRLEN vars, and the IV vars in which they stored as they are being normalised can already handle negative numbers. Putting the position and length into signed STRLEN vars instead of (signed) IV vars is not going to help simplify pp_substr any.

There are three ways of simplifying pp_substr:

Replies are listed 'Best First'.
Re^8: [OT] LLP64 .v. LP64 portability
by BrowserUk (Patriarch) on Apr 22, 2010 at 05:57 UTC

    I wasn't limiting my ambitions to simplifying just pp_substr, but ridding the sources of the 1302 size mismatches in 73 files under Win64. Many of these come about because values extracted from IVs are assigned to or mixed with STRLEN values.

    While casts cost nothing in runtime performance, adding all the pre-cast checks to ensure nothing will be lost does. And in 99% of cases totally unnecessarily.

    Update: By which I mean, if STRLEN has to be cast to size_t when calling memcpy or strlen, it costs nothing because a (positive) signed N-bit integer will always fit in an unsigned N-bit integer regardless and mean the same thing. So no pre-cast checks required.

    The essence of good software engineering is not the code you write, but the code you avoid writing.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      Could you please give an example where this would help? I am tired, but it sounds to me like you're trying to fix

      typedef size_t STRLEN; IV iv = -12; STRLEN len = iv; memcpy(src, dst, len);
      with
      typedef ptrdiff_t STRLEN; IV iv = -12; STRLEN len = iv; memcpy(src, dst, (size_t)len);

      Of course, that doesn't work. I don't see a case where casting would help. There's a reason casting is cheap.

        Of course, that doesn't work.... There's a reason casting is cheap.

        And there's a reason why you chose to post a non functional example.

        it costs nothing because a (positive) signed N-bit integer will always fit in an unsigned N-bit integer regardless and mean the same thing.

        And there is a reason why I belatedly added the highlghted parenthesised bit above despite that I originally omitted it because in the context of this discussion, it doesn't (rather shouldn't) need to be stated. But I knew who I was talking to.

        You know that neither snippet could ever make sense, so its use as an example to support your position is pointless. As is further discussion I fear. I thought (hoped) we'd got passed this, but I guess not.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.