Re: Why is this not a modifiable lvalue.

Discussion in 'C Programming' started by Dan Pop, Jun 27, 2003.

  1. Dan Pop

    Dan Pop Guest

    Try using gcc as a C compiler and it will no longer compile OK.
    Try using them as C compilers and they should produce one diagnostic.

    Most compilers are NOT conforming C compilers *by default*. You have to
    check their documentation to figure out how to invoke them as conforming
    C compilers (e.g. gcc needs -ansi -pedantic -ffloat-store).

    Dan
     
    Dan Pop, Jun 27, 2003
    #1
    1. Advertisements

  2. Dan Pop

    Dan Pop Guest

    -ffloat-store has precious little to do with IEEE floating-point:

    -ffloat-store
    Do not store floating point variables in registers.
    This prevents undesirable excess precision on ma­
    chines such as the 68000 where the floating regis­
    ters (of the 68881) keep more precision than a dou­
    ble is supposed to have.

    This can happen to both IEEE and non-IEEE floating point implementations.

    As the man page goes on to say, this is a non-issue for most programs,
    but there are rare cases when the exact semantics of f.p. arithmetic,
    as defined by the standard, are desired.

    Dan
     
    Dan Pop, Jun 27, 2003
    #2
    1. Advertisements


  3. If you don't specify it, what part of the C standard is it violating. Do you
    have an example?

    Carsten Hansen
     
    Carsten Hansen, Jun 27, 2003
    #3
  4. Yes, I'd be interested too. AFAIR the standard defines minimum
    precisions for types, not maximum.

    (And please, lets have a refefence, not ad hominem attacks. )
     
    Mark McIntyre, Jun 29, 2003
    #4
  5. Some relevant sections in the standard are here (from N869).

    5.1.2.3 Program execution
    ....
    [#13] EXAMPLE 4 Implementations employing wide registers have
    to take care to honor appropriate semantics. Values are
    independent of whether they are represented in a register
    or in memory. For example, an implicit spilling of a register
    is not permitted to alter the value. Also, an explicit store
    and load is required to round to the precision of the
    storage type. In particular, casts and assignments are
    required to perform their specified conversion. For the
    fragment
    double d1, d2;
    float f;
    d1 = f = expression;
    d2 = (float) expressions;

    the values assigned to d1 and d2 are required to have been
    converted to float.

    6.3.1.5 Real floating types

    [#2] When a double is demoted to float or a long double to
    double or float, if the value being converted is outside the
    range of values that can be represented, the behavior is
    undefined. If the value being converted is in the range of
    values that can be represented but cannot be represented
    exactly, the result is either the nearest higher or nearest
    lower value, chosen in an implementation-defined manner.

    and footnote 77 in N869 (which is footnote 86 in the Standard).

    77)If the value of the expression is represented with
    greater precision or range than required by the type
    named by the cast (6.3.1.8), then the cast specifies a
    conversion even if the type of the expression is the same
    as the named type.

    There were a few threads in comp.std.c on this topic last year.
    Clive Feather pointed out the above in the thread 'Floating-point
    semantics in C' on 4/16/2002.

    Regards,
    Bruce Wheeler
     
    Bruce Wheeler, Jun 30, 2003
    #5
  6. Dan Pop

    Dan Pop Guest

    I'm too lazy to search the relevant normative parts, so I'll only
    post a relevant example from the standard:

    12 EXAMPLE 4 Implementations employing wide registers have to take
    care to honor appropriate semantics. Values are independent
    of whether they are represented in a register or in memory. For
    example, an implicit spilling of a register is not permitted to
    alter the value. Also, an explicit store and load is required
    to round to the precision of the storage type. In particular,
    casts and assignments are required to perform their specified
    conversion. For the fragment

    double d1, d2;
    float f;
    d1 = f = expression;
    d2 = (float) expressions;

    the values assigned to d1 and d2 are required to have been
    converted to float.

    Without -ffloat-store, gcc on x86 will often perform optimisations not
    allowed by the text quoted above (e.g. using a temporary float may not
    result in reduced precision and casts to lower precision may often be
    ignored).

    Dik Winter could tell you a lot more on this topic, as he spent some time
    actually investigating the issue.

    Dan
     
    Dan Pop, Jun 30, 2003
    #6
  7. Dan Pop

    Dan Pop Guest

    How are you supposed to read my reply? ;-)

    Dan
     
    Dan Pop, Jun 30, 2003
    #7
    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.