[Pdx-pm] off-topic: C90 declaration question

Jon LeVitre jonlevitre at yahoo.com
Mon Apr 17 14:56:10 PDT 2006



--- Marvin Humphrey <marvin at rectangular.com> wrote:

> 
> It gets murkier.  Seemingly, you can even do this under C90, as gcc  
> doesn't complain:
> 
>  int
>  meaning_of_life() {
>    int i = function_which_returns_forty_one(); /* NOT "code"?! */
>    int j = 1;
>    return i + j;
>  }
> 
> BUT... you *can't* do this:
> 
>  int
>  meaning_of_life() {
>    int i;
>    i = function_which_returns_forty_one();     /* "code" !! */
>    int j = 1;      /* BZZT! Too late to declare a variable. */
>    return i + j;
>  }
> 
> ... and that's where my bafflement becomes total.  Tell me, how is  
> that any more difficult for the compiler writer than the previous  
> example?
> 
> Here's my question: Can the right hand side of a C90 declaration/ 
> initialization contain an arbitrarily complex expression?
> 

I think the distinction isn't between code and non-code, but
declaration statements and non-declaration statements

There's no reason why a compiler can't generate the code for
arbitrarily complex expressions in initialization statements.  It could
generate the same object code in either case, it just choses not to if
your code doesn't look "right" (a declaration statement after a
non-declaration statement isn' "right").  

It's trying to protect you from yourself.  

Jon

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


More information about the Pdx-pm-list mailing list