Sizes of pointers

Discussion in 'C Programming' started by James Harris \(es\), Jul 30, 2013.

  1. Am 06.08.2013 15:06, schrieb Stephen Sprunk:
    Java was never designed to be compatible between 2 dOSes even on exactly
    the same hardware.

    I have seen that big fault myself in having one big JAVA application
    written under OS/2 32 bit getting segfault in Windows NT on the same
    mashine with both running exactly the same java version on both.

    I've written some applications in C running on OS/2, sinix HPux, windows
    and others without changing a little bit. Impossible with Java!
     
    Herbert Rosenau, Aug 12, 2013
    1. Advertisements

  2. This is off topic, but my understanding is that Java was *designed* to
    be compatible across different operating systems. Whether it actually
    met that design goal is another question
    I suppose that depends on the application.
     
    Keith Thompson, Aug 12, 2013
    1. Advertisements

  3. That's what I understood too.
    The idea was that a program would have exactly the same output, regardless
    of the OS. That wasn't possible in an absolute sense, because you could
    tell whether you were on Windows or Unix by the path separator, so a
    malicious programmer could write code deliberately designed to break on
    one OS. But that was only a minor caveat.
    Then floating point conformity had to be abandoned, for efficiency reasons.
    Again this didn't matter much in the real world, but it did mean that if
    you had sloppily-written code, you might get different rounding artifacts.
     
    Malcolm McLean, Aug 12, 2013
  4. 在 2013å¹´7月30日星期二UTC+8下åˆ6æ—¶02分45秒,James Harris写é“:
    in generally , it is 4-byte
     
    赟 张, Aug 13, 2013
  5. James Harris \(es\)

    James Kuyper Guest

    On 08/13/2013 03:16 AM, 赟 张 wrote:
    [Re: pointers]
    On many systems, that's true, though it would be stupid to build that
    assumption into code intended to be portable. There's a reason why
    sizeof() exists - use it.
    But this thread is not about such systems - it's about systems where
    pointers can have two or more different sizes, or more generally, two or
    more different representations.
     
    James Kuyper, Aug 13, 2013
  6. I deny that it's "equally reasonable" to describe something universally
    known as "sign extension" with an invented term that serves only to
    remove the term "sign" from an explanation of pointers, especially when
    the same documents call that same something "sign extension" when
    applied to any other type of value.

    Yes, it can be done, but that doesn't make it "equally reasonable".

    S
     
    Stephen Sprunk, Aug 13, 2013
  7. James Harris \(es\)

    Philip Lantz Guest


    In the following example, assume that the array 'arr' is at address
    0xffffffff80001000, in what I would call the negative part of the
    address space, which you say is a matter of opinion.

    Note that the exact same instruction and encoding are used for the two
    examples. In both cases, the 32-bit constant part of the address is
    sign-extended as part of address calculation. Is it your contention that
    calling -200 negative is also a matter of opinion?


    extern char arr[];

    void f(char *p)
    {
    p[-200] = 0; // movb -200[rdi], 0 c6 87 38 ff ff ff 00
    }

    void g(size_t i)
    {
    a = 0; // movb a[rdi], 0 c6 87 00 10 00 80 00
    }

    (I did the instruction selection and encoding by hand; I hope I didn't
    make an error. But even if I did, the point remains valid.)

    Philip
     
    Philip Lantz, Aug 17, 2013
  8. Given a suitable definition of color, sure they do.
    We'll have to agree to disagree on that, then, because IMHO inventors
    _do_ have the authority to define their inventions as they see fit.
    Some documentation, but not all.
    IMHO, if it contradicts the inventors, it is not a valid authority.
    You well know that, on a twos-complement system, if the top bit of a
    value is replicated when copied to a larger register, that is called
    "sign extension". To call it anything else is an blatant attempt to
    obfuscate the behavior.

    You also know that sign extension (or whatever you want to call it) is
    only used on signed values. If a value is unsigned, you would use zero
    extension (or whatever you want to call it) instead.
    Compare these two explanations:

    1. Pointers are signed.

    2. Pointers are unsigned, but when copying them to a larger register you
    use sign extension, though it's not called sign extension, rather than
    zero extension, which is used for unsigned values of other types.

    I dare you to come up with _any_ measure of simplicity, elegance or
    self-consistency that does not favor the first option.

    S
     
    Stephen Sprunk, Aug 18, 2013
  9. James Harris \(es\)

    Tim Rentsch Guest

    Ahh, I see what you're driving at. You want the C code and Java
    code to be able to interoperate.

    My assumption is different from yours. I assume the point of
    compiling C code to a JVM is so the C code can execute in the JVM
    environment, which might not otherwise have a readily usable C
    compiler. If one wanted C and Java to able to interoperate, and
    do so tolerably well, that really needs some degree of changes to
    the language(s), not just the compilers.
     
    Tim Rentsch, Aug 19, 2013
  10. James Harris \(es\)

    Tim Rentsch Guest

    None of these comments has any bearing on what I was
    saying.
     
    Tim Rentsch, Aug 19, 2013
  11. James Harris \(es\)

    Tim Rentsch Guest

    The two situations have nothing to do with each other. In the
    first case the scheme being described is fixed but different
    descriptions are offered. In the second case two different
    schemes are considered (compared, contrasted, etc). Trying
    to draw parallels between them is nonsensical.
     
    Tim Rentsch, Aug 19, 2013
  12. James Harris \(es\)

    Tim Rentsch Guest

    Obviously how pointers work on x86-64 is not universally known
    as sign extension, as there are numerous examples of documents
    that describe it using different terms.

    More importantly, the point of my comment was not about the
    term "sign extension" but the concept of sign extension. By
    analogy, inverting all the bits of a computer word can be seen
    either as logical complementation or as negation under a ones
    complement representation. Whatever name the operation code
    happens to have, we conceptualize the operation in different
    ways, depending how we view the spaces of values represented.
    Similarly, just because how pointer expansion works happens to
    match a mechanism named "sign extension", that doesn't mean we
    must necessarily impute the concepts of signed values to the
    bits being operated on, and different conceptualizations will
    naturally lead to different descriptions.
    I don't see any support for this position other than your
    repeated assertion that it must be so.
     
    Tim Rentsch, Aug 21, 2013
  13. James Harris \(es\)

    Tim Rentsch Guest

    If you read the previous posting again, I believe you will see
    that my comment is about which view makes more sense, not about
    whether believing addresses are signed is an opinion. I don't
    think there is any debate about whether addresses are "truly
    signed", only about whether it's more convenient to think of them
    that way.


    The abstract value -200 is certainly negative; that is true by
    definition.

    The operand part of the instruction (ie, the bits corresponding
    to the '38 ff ff ff' byte values) is certainly not negative.
    Neither is it positive. Only numbers are positive or negative;
    the operand portion of the instruction is just a collection of
    bits, not a number.

    The question then becomes what do we consider those bits as
    representing? We might consider them as representing a signed
    value (ie, -200); or, we might consider them as representing a
    large unsigned value, which has the same effect under the rules
    of unsigned arithmetic as subtracting 200. The second view is
    like what happens in C when we add a negative signed value to an
    unsigned value, eg

    unsigned u = 1000;
    u = -200 + u;

    After the assignment u will have the value 800. However, what is
    being added to u is not (under the semantic rules of the C
    abstract machine) a negative value, but rather a large unsigned
    value.

    Moreover, note that the instructions and formats being used here
    are regular x86 instructions (ie, not specific to x86-64).
    Before the x86-64, addresses in x86 were not thought of as
    being signed. So there is some precedent for the idea that
    what is being represented in the operand field is a large
    unsigned value rather than a signed value.
    Everyone agrees that the mechanism of address expansion in x86-64
    is isomorphic to the mechanism of sign extension. Does this mean
    these addresses _must_ be seen as being signed? Of course it
    doesn't. Lots of people prefer that view, but certainly there
    are equally consistent views that do not treat addresses as being
    signed. Which view is more convenient? Obviously different
    people have different opinions on that question. All I'm saying
    is the last question has no absolute answer.
     
    Tim Rentsch, Aug 21, 2013
  14. James Harris \(es\)

    Tim Rentsch Guest

    In the first place, it was you who made the claim, not me. If
    there a burden to be borne here, such as coming up with a
    measure, it is you who bear it -- if you can't support your own
    claim, it is simply an unsupported claim, and no disproof
    required. I have made no claims about which view is simpler,
    etc, either objectively or otherwise.

    In the second place, it is trivial to come up with a measure that
    favors the second option over the first, eg, "longer explanations
    are more elegant than shorter explanations".

    In the third place, what you apparently fail to understand is
    that the issue here is not to define a _measure_, but to describe
    a means to perform an objective _measurement_, where the result
    of the measurement mechanism is both objective and corresponds
    to what most people would agree is simple, elegant, and
    self-consistent. The claim about which view is simpler, etc,
    has meaning only if those words have a previously agreed upon
    meaning -- if someone is going to define their meaning after
    the fact, any claim about which view is simpler, etc, is a
    completely empty statement.
     
    Tim Rentsch, Aug 22, 2013
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.