C return a++ - is it safe?

Discussion in 'C Programming' started by James Harris, Oct 29, 2007.

  1. James Harris

    James Harris Guest

    If in C one codes a function which includes

    return a++;

    does 'a' get incremented? Would the behaviour be safe to rely upon? I
    guess this might apply if 'a' were static or such as

    return ptr->element++;

    I didn't find this in the comp.lang.c faq (at least the first one that
    came up from Google; there seemed to be many) but didn't find it. No
    doubt someone will tell me where I should have looked.

    (For the time being I'm coding: a++; return a - 1; )
    --
    James
     
    James Harris, Oct 29, 2007
    #1
    1. Advertising

  2. "James Harris" <> schrieb im Newsbeitrag
    news:...
    > If in C one codes a function which includes
    >
    > return a++;
    >
    > does 'a' get incremented? Would the behaviour be safe to rely upon? I
    > guess this might apply if 'a' were static or such as
    >
    > return ptr->element++;
    >
    > I didn't find this in the comp.lang.c faq (at least the first one that
    > came up from Google; there seemed to be many) but didn't find it. No
    > doubt someone will tell me where I should have looked.
    >
    > (For the time being I'm coding: a++; return a - 1; )

    It is safe as ; constitutes a sequence point

    Bye, Jojo
     
    Joachim Schmitz, Oct 29, 2007
    #2
    1. Advertising

  3. [comp.lang.c] Joachim Schmitz <> wrote:

    > "James Harris" <> schrieb im Newsbeitrag
    > news:...
    >> If in C one codes a function which includes
    >>
    >> return a++;
    >>
    >> does 'a' get incremented?


    Yes.

    >> Would the behaviour be safe to rely upon?


    Yes.

    >> I didn't find this in the comp.lang.c faq (at least the first one that
    >> came up from Google; there seemed to be many) but didn't find it. No
    >> doubt someone will tell me where I should have looked.


    I imagine K&R explains the issue, but if you looked there and still
    weren't sure, this is an appropriate venue for the question - I'm
    pretty sure it's not in the FAQ.

    >> (For the time being I'm coding: a++; return a - 1; )

    > It is safe as ; constitutes a sequence point


    That's true, but that wasn't OP's question.

    --
    C. Benson Manica | I appreciate all corrections, polite or otherwise.
    cbmanica(at)gmail.com |
    ----------------------| I do not currently read any posts posted through
    sdf.lonestar.org | Google groups, due to rampant unchecked spam.
     
    Christopher Benson-Manica, Oct 29, 2007
    #3
  4. Christopher Benson-Manica wrote:
    >
    > [comp.lang.c] Joachim Schmitz <> wrote:
    >
    > > "James Harris" <> schrieb im Newsbeitrag
    > > news:...
    > >> If in C one codes a function which includes
    > >>
    > >> return a++;
    > >>
    > >> does 'a' get incremented?

    [...]
    > >> (For the time being I'm coding: a++; return a - 1; )

    > > It is safe as ; constitutes a sequence point

    >
    > That's true, but that wasn't OP's question.


    Indirectly, it is. The increment is guaranteed to take place by
    the time the sequence point is "reached". Therefore, the increment
    is guaranteed to be done before the return completes.

    However, if "a" were a non-static non-volatile automatic variable,
    can the compiler skip the increment? I believe so, because it will
    go out of scope upon executing the return, and the result is "as
    if" the increment were actually done.

    --
    +-------------------------+--------------------+-----------------------+
    | Kenneth J. Brody | www.hvcomputer.com | #include |
    | kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
    +-------------------------+--------------------+-----------------------+
    Don't e-mail me at: <mailto:>
     
    Kenneth Brody, Oct 29, 2007
    #4
  5. Kenneth Brody <> writes:
    > Christopher Benson-Manica wrote:
    >> [comp.lang.c] Joachim Schmitz <> wrote:
    >> > "James Harris" <> schrieb im Newsbeitrag
    >> > news:...
    >> >> If in C one codes a function which includes


    >> >> return a++;
    >> >>
    >> >> does 'a' get incremented?

    > [...]
    >> >> (For the time being I'm coding: a++; return a - 1; )
    >> > It is safe as ; constitutes a sequence point

    >>
    >> That's true, but that wasn't OP's question.

    >
    > Indirectly, it is. The increment is guaranteed to take place by
    > the time the sequence point is "reached". Therefore, the increment
    > is guaranteed to be done before the return completes.
    >
    > However, if "a" were a non-static non-volatile automatic variable,
    > can the compiler skip the increment? I believe so, because it will
    > go out of scope upon executing the return, and the result is "as
    > if" the increment were actually done.


    The OP specifically mentioned the case where ``a'' is not local to the
    function.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Oct 29, 2007
    #5
  6. James Harris

    Chris Hills Guest

    In article <>, Keith Thompson
    <> writes
    >Kenneth Brody <> writes:
    >> Christopher Benson-Manica wrote:
    >>> [comp.lang.c] Joachim Schmitz <> wrote:
    >>> > "James Harris" <> schrieb im Newsbeitrag
    >>> > news:...
    >>> >> If in C one codes a function which includes

    >
    >>> >> return a++;
    >>> >>
    >>> >> does 'a' get incremented?

    >> [...]
    >>> >> (For the time being I'm coding: a++; return a - 1; )
    >>> > It is safe as ; constitutes a sequence point
    >>>
    >>> That's true, but that wasn't OP's question.

    >>
    >> Indirectly, it is. The increment is guaranteed to take place by
    >> the time the sequence point is "reached". Therefore, the increment
    >> is guaranteed to be done before the return completes.
    >>
    >> However, if "a" were a non-static non-volatile automatic variable,
    >> can the compiler skip the increment? I believe so, because it will
    >> go out of scope upon executing the return, and the result is "as
    >> if" the increment were actually done.

    >
    >The OP specifically mentioned the case where ``a'' is not local to the
    >function.


    Regardless of the standard(s) I think this is one you would need to
    empirically test of the compiler(s) in question.

    If this were Ada one could just refer to the standard but it's C and
    nothing is guaranteed.
    --
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
    \/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
    /\/\/ www.phaedsys.org \/\/\
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
     
    Chris Hills, Oct 30, 2007
    #6
  7. James Harris

    pete Guest

    James Harris wrote:
    >
    > If in C one codes a function which includes
    >
    > return a++;
    >
    > does 'a' get incremented?


    Yes.

    > Would the behaviour be safe to rely upon?


    Yes.

    > I guess this might apply if 'a' were static


    Yes.

    --
    pete
     
    pete, Oct 30, 2007
    #7
  8. Chris Hills <> writes:
    > In article <>, Keith Thompson
    > <> writes
    >>Kenneth Brody <> writes:
    >>> Christopher Benson-Manica wrote:
    >>>> [comp.lang.c] Joachim Schmitz <> wrote:
    >>>> > "James Harris" <> schrieb im Newsbeitrag
    >>>> > news:...
    >>>> >> If in C one codes a function which includes
    >>>> >> return a++;
    >>>> >>
    >>>> >> does 'a' get incremented?
    >>> [...]
    >>>> >> (For the time being I'm coding: a++; return a - 1; )
    >>>> > It is safe as ; constitutes a sequence point
    >>>>
    >>>> That's true, but that wasn't OP's question.
    >>>
    >>> Indirectly, it is. The increment is guaranteed to take place by
    >>> the time the sequence point is "reached". Therefore, the increment
    >>> is guaranteed to be done before the return completes.
    >>>
    >>> However, if "a" were a non-static non-volatile automatic variable,
    >>> can the compiler skip the increment? I believe so, because it will
    >>> go out of scope upon executing the return, and the result is "as
    >>> if" the increment were actually done.

    >>
    >>The OP specifically mentioned the case where ``a'' is not local to the
    >>function.

    >
    > Regardless of the standard(s) I think this is one you would need to
    > empirically test of the compiler(s) in question.
    >
    > If this were Ada one could just refer to the standard but it's C and
    > nothing is guaranteed.


    Huh?

    The C standard defines how the return statement and the "++" operator
    work. If ``return a++;'' doesn't increment ``a'' (other than in cases
    covered by the as-if rule), then the compiler is broken.

    The C and Ada standards are both written in English, and in fairly
    similar styles. C leaves more things undefined than Ada does, but
    it's reasonably clear about *what* it leaves undefined.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Oct 30, 2007
    #8
  9. On Tue, 30 Oct 2007 02:03:23 -0700, Keith Thompson
    <> wrote:

    >Chris Hills <> writes:
    >> In article <>, Keith Thompson
    >> <> writes
    >>>Kenneth Brody <> writes:
    >>>> Christopher Benson-Manica wrote:
    >>>>> [comp.lang.c] Joachim Schmitz <> wrote:
    >>>>> > "James Harris" <> schrieb im Newsbeitrag
    >>>>> > news:...
    >>>>> >> If in C one codes a function which includes
    >>>>> >> return a++;
    >>>>> >>
    >>>>> >> does 'a' get incremented?
    >>>> [...]
    >>>>> >> (For the time being I'm coding: a++; return a - 1; )
    >>>>> > It is safe as ; constitutes a sequence point
    >>>>>
    >>>>> That's true, but that wasn't OP's question.
    >>>>
    >>>> Indirectly, it is. The increment is guaranteed to take place by
    >>>> the time the sequence point is "reached". Therefore, the increment
    >>>> is guaranteed to be done before the return completes.
    >>>>
    >>>> However, if "a" were a non-static non-volatile automatic variable,
    >>>> can the compiler skip the increment? I believe so, because it will
    >>>> go out of scope upon executing the return, and the result is "as
    >>>> if" the increment were actually done.
    >>>
    >>>The OP specifically mentioned the case where ``a'' is not local to the
    >>>function.

    >>
    >> Regardless of the standard(s) I think this is one you would need to
    >> empirically test of the compiler(s) in question.
    >>
    >> If this were Ada one could just refer to the standard but it's C and
    >> nothing is guaranteed.

    >
    >Huh?
    >
    >The C standard defines how the return statement and the "++" operator
    >work. If ``return a++;'' doesn't increment ``a'' (other than in cases
    >covered by the as-if rule), then the compiler is broken.
    >
    >The C and Ada standards are both written in English, and in fairly
    >similar styles. C leaves more things undefined than Ada does, but
    >it's reasonably clear about *what* it leaves undefined.


    I believe you're missing his point. Ada has a very thorough
    validation suite and stringent restrictions on what may be called
    an Ada compiler. This isn't the case with C compilers; anybody
    can produce what they call a C compiler. It is even possible
    that there is no such thing as a fully conforming C compiler.

    His point is that in the real world this is the kind of thing
    that you should check whether the compiler gets it right. Off
    hand, I would think that it is the sort of thing that a compiler
    could be expected to get right but I might well be wrong.




    Richard Harter,
    http://home.tiac.net/~cri, http://www.varinoma.com
    In the fields of Hell where the grass grows high
    Are the graves of dreams allowed to die
     
    Richard Harter, Oct 30, 2007
    #9
  10. James Harris

    Larry__Weiss Guest

    Richard Harter wrote:
    > I believe you're missing his point. Ada has a very thorough
    > validation suite and stringent restrictions on what may be called
    > an Ada compiler. This isn't the case with C compilers; anybody
    > can produce what they call a C compiler. It is even possible
    > that there is no such thing as a fully conforming C compiler.
    >
    > His point is that in the real world this is the kind of thing
    > that you should check whether the compiler gets it right. Off
    > hand, I would think that it is the sort of thing that a compiler
    > could be expected to get right but I might well be wrong.
    >


    Do set of programs exist that attempt to validate a C implementation?

    If so, are any of these freely available?

    - Larry
     
    Larry__Weiss, Oct 30, 2007
    #10
  11. James Harris

    Chris Hills Guest

    In article <>, Larry__Weiss
    <> writes
    >Richard Harter wrote:
    >> I believe you're missing his point. Ada has a very thorough
    >> validation suite and stringent restrictions on what may be called
    >> an Ada compiler. This isn't the case with C compilers; anybody
    >> can produce what they call a C compiler. It is even possible
    >> that there is no such thing as a fully conforming C compiler.
    >> His point is that in the real world this is the kind of thing
    >> that you should check whether the compiler gets it right. Off
    >> hand, I would think that it is the sort of thing that a compiler
    >> could be expected to get right but I might well be wrong.
    >>

    >
    >Do set of programs exist that attempt to validate a C implementation?


    Yes

    >If so, are any of these freely available?


    No

    --
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
    \/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
    /\/\/ www.phaedsys.org \/\/\
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
     
    Chris Hills, Oct 30, 2007
    #11
  12. James Harris

    Chris Hills Guest

    In article <>, pete <>
    writes
    >James Harris wrote:
    >>
    >> If in C one codes a function which includes
    >>
    >> return a++;
    >>
    >> does 'a' get incremented?

    >
    >Yes.
    >
    >> Would the behaviour be safe to rely upon?

    >
    >Yes.
    >
    >> I guess this might apply if 'a' were static

    >
    >Yes.


    Oh dear.......

    --
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
    \/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
    /\/\/ www.phaedsys.org \/\/\
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
     
    Chris Hills, Oct 30, 2007
    #12
  13. James Harris

    Chris Hills Guest

    In article <>, Richard Harter
    <> writes
    >On Tue, 30 Oct 2007 02:03:23 -0700, Keith Thompson
    ><> wrote:
    >
    >>Chris Hills <> writes:
    >>> In article <>, Keith Thompson
    >>> <> writes
    >>>>Kenneth Brody <> writes:
    >>>>> Christopher Benson-Manica wrote:
    >>>>>> [comp.lang.c] Joachim Schmitz <> wrote:
    >>>>>> > "James Harris" <> schrieb im Newsbeitrag
    >>>>>> > news:...
    >>>>>> >> If in C one codes a function which includes
    >>>>>> >> return a++;
    >>>>>> >>
    >>>>>> >> does 'a' get incremented?
    >>>>> [...]
    >>>>>> >> (For the time being I'm coding: a++; return a - 1; )
    >>>>>> > It is safe as ; constitutes a sequence point
    >>>>>>
    >>>>>> That's true, but that wasn't OP's question.
    >>>>>
    >>>>> Indirectly, it is. The increment is guaranteed to take place by
    >>>>> the time the sequence point is "reached". Therefore, the increment
    >>>>> is guaranteed to be done before the return completes.
    >>>>>
    >>>>> However, if "a" were a non-static non-volatile automatic variable,
    >>>>> can the compiler skip the increment? I believe so, because it will
    >>>>> go out of scope upon executing the return, and the result is "as
    >>>>> if" the increment were actually done.
    >>>>
    >>>>The OP specifically mentioned the case where ``a'' is not local to the
    >>>>function.
    >>>
    >>> Regardless of the standard(s) I think this is one you would need to
    >>> empirically test of the compiler(s) in question.
    >>>
    >>> If this were Ada one could just refer to the standard but it's C and
    >>> nothing is guaranteed.

    >>
    >>Huh?
    >>
    >>The C standard defines how the return statement and the "++" operator
    >>work. If ``return a++;'' doesn't increment ``a'' (other than in cases
    >>covered by the as-if rule), then the compiler is broken.
    >>
    >>The C and Ada standards are both written in English, and in fairly
    >>similar styles. C leaves more things undefined than Ada does, but
    >>it's reasonably clear about *what* it leaves undefined.

    >
    >I believe you're missing his point. Ada has a very thorough
    >validation suite and stringent restrictions on what may be called
    >an Ada compiler. This isn't the case with C compilers; anybody
    >can produce what they call a C compiler. It is even possible
    >that there is no such thing as a fully conforming C compiler.
    >
    >His point is that in the real world this is the kind of thing
    >that you should check whether the compiler gets it right.


    Precisely

    > Off
    >hand, I would think that it is the sort of thing that a compiler
    >could be expected to get right but I might well be wrong.


    In other words you wouldn't bet your life on it....

    --
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
    \/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
    /\/\/ www.phaedsys.org \/\/\
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
     
    Chris Hills, Oct 30, 2007
    #13
  14. On Tue, 30 Oct 2007 15:34:32 GMT, in comp.lang.c ,
    (Richard Harter) wrote:

    >Ada has a very thorough
    >validation suite and stringent restrictions on what may be called
    >an Ada compiler. This isn't the case with C compilers; anybody
    >can produce what they call a C compiler.


    But this is only true to the same extent that anyone can produce
    something they call an Ada compiler. For instance AFAIK its not
    actually illegal in the UK or US to call your firstborn child "An Ada
    Compiler".

    >It is even possible
    >that there is no such thing as a fully conforming C compiler.


    *shrug*. And possibly there are no general purpose multiplatform Ada
    compilers either.

    I think your point is moot since Ada and C have different uses and
    scopes. Any discussion is likely to be as sensible as debating whether
    fish are more useful than footballs. The answer is "it depends".

    --
    Mark McIntyre

    "Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are,
    by definition, not smart enough to debug it."
    --Brian Kernighan
     
    Mark McIntyre, Oct 30, 2007
    #14
  15. James Harris

    Martin Wells Guest

    Kenneth:

    > However, if "a" were a non-static non-volatile automatic variable,
    > can the compiler skip the increment? I believe so, because it will
    > go out of scope upon executing the return, and the result is "as
    > if" the increment were actually done.



    If the local variable were neither volatile nor static, then the
    increment is utterly redundant... and I wouldn't mind the compiler
    issuing a warning something like:

    WARNING: Redundant operation on local automatic variable

    Only two reasons come to mind as to why you'd have a redundant
    operation on a local automatic variable:

    1) You intended to define it as either static or volatile.
    2) You're stupid.

    Martin
     
    Martin Wells, Oct 30, 2007
    #15
  16. James Harris

    CBFalconer Guest

    Chris Hills wrote:
    > Larry__Weiss <> writes
    >

    .... snip ...
    >
    >> Do set of programs exist that attempt to validate a C
    >> implementation?

    >
    > Yes
    >
    >> If so, are any of these freely available?

    >
    > No


    Yes. The gcc test suite is freely available. However it is geared
    to "gcc C" rather than ISO std C.

    --
    Chuck F (cbfalconer at maineline dot net)
    Available for consulting/temporary embedded and systems.
    <http://cbfalconer.home.att.net>



    --
    Posted via a free Usenet account from http://www.teranews.com
     
    CBFalconer, Oct 30, 2007
    #16
  17. [... Talking about "return a++;" ...]

    Martin Wells wrote:
    >
    > Kenneth:
    >
    > > However, if "a" were a non-static non-volatile automatic variable,
    > > can the compiler skip the increment? I believe so, because it will
    > > go out of scope upon executing the return, and the result is "as
    > > if" the increment were actually done.

    >
    > If the local variable were neither volatile nor static, then the
    > increment is utterly redundant... and I wouldn't mind the compiler
    > issuing a warning something like:
    >
    > WARNING: Redundant operation on local automatic variable


    "Redundant", or "useless"?

    > Only two reasons come to mind as to why you'd have a redundant
    > operation on a local automatic variable:
    >
    > 1) You intended to define it as either static or volatile.
    > 2) You're stupid.


    3) You're wondering whether your compiler will optimize it away.

    --
    +-------------------------+--------------------+-----------------------+
    | Kenneth J. Brody | www.hvcomputer.com | #include |
    | kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
    +-------------------------+--------------------+-----------------------+
    Don't e-mail me at: <mailto:>
     
    Kenneth Brody, Oct 30, 2007
    #17
  18. Chris Hills <> writes:
    > In article <>, Richard Harter
    > <> writes
    >>On Tue, 30 Oct 2007 02:03:23 -0700, Keith Thompson
    >><> wrote:
    >>>Chris Hills <> writes:

    [...]
    >>>> Regardless of the standard(s) I think this is one you would need to
    >>>> empirically test of the compiler(s) in question.
    >>>>
    >>>> If this were Ada one could just refer to the standard but it's C and
    >>>> nothing is guaranteed.
    >>>
    >>>Huh?
    >>>
    >>>The C standard defines how the return statement and the "++" operator
    >>>work. If ``return a++;'' doesn't increment ``a'' (other than in cases
    >>>covered by the as-if rule), then the compiler is broken.
    >>>
    >>>The C and Ada standards are both written in English, and in fairly
    >>>similar styles. C leaves more things undefined than Ada does, but
    >>>it's reasonably clear about *what* it leaves undefined.

    >>
    >>I believe you're missing his point. Ada has a very thorough
    >>validation suite and stringent restrictions on what may be called
    >>an Ada compiler. This isn't the case with C compilers; anybody
    >>can produce what they call a C compiler. It is even possible
    >>that there is no such thing as a fully conforming C compiler.
    >>
    >>His point is that in the real world this is the kind of thing
    >>that you should check whether the compiler gets it right.

    >
    > Precisely
    >
    >> Off
    >>hand, I would think that it is the sort of thing that a compiler
    >>could be expected to get right but I might well be wrong.

    >
    > In other words you wouldn't bet your life on it....


    All software (including compilers) has bugs. All software should be
    thoroughly tested. But a compiler bug in the handling of ``return
    a++;'' is quite low on the list of things I'd worry about -- higher
    than ``1 + 1 == 2'', lower than, say, some obscure C99 feature, and
    about the same as ``return (a = 42);''.

    Consider how the return statement is defined: the expression is
    evaluated, and the result is returned. Updating ``a'' is part of the
    evaluation of the expression.

    Is there some particular reason you're concerned that a compiler might
    handle something this simple incorrectly?

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Oct 30, 2007
    #18
  19. "Martin Wells" <> a écrit dans le message de news:
    ...
    > Kenneth:
    >
    >> However, if "a" were a non-static non-volatile automatic variable,
    >> can the compiler skip the increment? I believe so, because it will
    >> go out of scope upon executing the return, and the result is "as
    >> if" the increment were actually done.

    >
    > If the local variable were neither volatile nor static, then the
    > increment is utterly redundant... and I wouldn't mind the compiler
    > issuing a warning something like:
    >
    > WARNING: Redundant operation on local automatic variable
    >
    > Only two reasons come to mind as to why you'd have a redundant
    > operation on a local automatic variable:
    >
    > 1) You intended to define it as either static or volatile.
    > 2) You're stupid.


    Or you could be using macros with side effects:

    #define GETBYTE(p) (*(p)++ & 0xFF)

    int safegetbyte(const char *s) {
    if (!s)
    return -1;
    return GETBYTE(s);
    }

    --
    Chqrlie.
     
    Charlie Gordon, Oct 30, 2007
    #19
  20. James Harris

    Tor Rustad Guest

    Chris Hills wrote:

    [...]

    > Regardless of the standard(s) I think this is one you would need to
    > empirically test of the compiler(s) in question.
    >
    > If this were Ada one could just refer to the standard but it's C and
    > nothing is guaranteed.


    Well, some C compilers has been validated:

    http://www.peren.com/pages/cvsa_set.htm
    http://www.plumhall.com/stec.html

    and at this point, the C90 test cases should detect such an compiler
    bug. However, in safety-critical SW, I wouldn't advocate using construct
    like

    return a++;

    anyway.

    --
    Tor < | tr i-za-h a-z>
     
    Tor Rustad, Oct 30, 2007
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gabriel Rossetti
    Replies:
    0
    Views:
    1,398
    Gabriel Rossetti
    Aug 29, 2008
  2. Replies:
    1
    Views:
    375
    Brian Candler
    Aug 12, 2003
  3. Aredridel

    Not just $SAFE, but damn $SAFE

    Aredridel, Sep 2, 2004, in forum: Ruby
    Replies:
    19
    Views:
    266
  4. Farrel Lifson

    $SAFE =4 safe enough?

    Farrel Lifson, Aug 29, 2006, in forum: Ruby
    Replies:
    7
    Views:
    120
    Eric Hodel
    Aug 31, 2006
  5. John Nagle
    Replies:
    5
    Views:
    512
    John Nagle
    Mar 12, 2012
Loading...

Share This Page