Re: Order of evaluation.

From: Jason (spacenjasset_at_fastmail.fm)
Date: 02/11/04


Date: Wed, 11 Feb 2004 16:02:51 -0000


"Richard Heathfield" <invalid@address.co.uk.invalid> wrote in message
news:402a4aec@news2.power.net.uk...
> To be frank, neither do I! That is, I know it's either unspecified
behaviour
> or undefined behaviour. I suspect the latter, but can't prove it without
> digging out the Standard (and I might just end up proving myself wrong).
> But the *important* thing about the code, the "right" answer if you like,
> is "this code is stupid stupid stupid and don't /ever/ let me catch you
> doing this, okay?". :-)

I won't do that. I would do a++ before calling the function.

> It does indeed. If the interviewer doesn't know that this is valid, and
> *why* it is valid, he or she has no business testing other people's C
> knowledge.

That is how I feel, although I appreciate that someone that knows the finer
points of C, will most proably be a "well rounded" programmer.

> > Sophos have a reputation for "difficult" C tests, but I find it strange
> > that they don't know about the above construct.
>
> It seems they find C rather difficult.
>
>
> > Good job I didn't write this then, which I believe is also valid, but
> > unnecessary ( sizeof introduces the tag name a_struct in this context ):
> >
> > {
> > size_t size = sizeof ( struct a_struct { int a; } );
> >
> > s = malloc( sizeof (a_struct) );
> > }
>
> I think you might want to run this one by your compiler before you get too
> fond of it. :-)

Ah - it doesn't work then? I am not fond of it (never tried it). I read that
in 1994, Samuel P. Harbison, et al., "C A Reference Manual", ISBN
0-13-326224-3, page 196

"The effect of sizeof(struct S {int a,b;} ) is to create a new type [S] in
ISO C, [cut], the type can be referenced later in the source file."

Took me ages to find that reference.



Relevant Pages

  • Re: C Standard Regarding Null Pointer Dereferencing
    ... person's frame of reference. ... unsatisfactory responses, and must admit having neglected this ... according to the semantics without invoking undefined behaviour? ... due to ambiguity in the referenced draft. ...
    (comp.lang.c)
  • Re: REFERENCES REVEALED
    ... >> reference can bind to a temporary, ... > temporaries, I'd appreciate it. ... The above is undefined behaviour. ...
    (comp.lang.cpp)
  • Re: Returning NULL references...
    ... Andre Kostur wrote in ... > An exception. ... Or leave it as undefined behaviour. ... I need to return a reference ...
    (comp.lang.cpp)
  • Re: list.remove() crash.
    ... You are iterating through the list and deleting from it at the same time. ... suspect this will cause undefined behaviour. ...
    (microsoft.public.vc.mfc)
  • Re: null references
    ... void Func ... it's undefined behaviour so it doesn't qualify as ... You can't legally dereference a null pointer nor is a null ... reference legally possible. ...
    (microsoft.public.dotnet.languages.csharp)