Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > The order of block declaration

Reply
Thread Tools

The order of block declaration

 
 
lovecreatesbea...@gmail.com
Guest
Posts: n/a
 
      02-08-2008
Hi!

`declaration' appears before `statement' within local block in the
following diagram. So, does C specify the order of block declaration
just by this? Is there other description about the order of block
declaration? I can't find it in n1124.pdf.

<quote>
(6.8.2) block-item:
declaration
statement
</quote>

Thank you for your time.
 
Reply With Quote
 
 
 
 
santosh
Guest
Posts: n/a
 
      02-08-2008
(E-Mail Removed) wrote:

> Hi!
>
> `declaration' appears before `statement' within local block in the
> following diagram. So, does C specify the order of block declaration
> just by this? Is there other description about the order of block
> declaration? I can't find it in n1124.pdf.
>
> <quote>
> (6.8.2) block-item:
> declaration
> statement
> </quote>
>
> Thank you for your time.


C99 allows mixed code and declarations. All versions of C before C99
mandated that declarations precede code within a block.

 
Reply With Quote
 
 
 
 
lovecreatesbea...@gmail.com
Guest
Posts: n/a
 
      02-08-2008
On Feb 9, 12:13*am, santosh <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote:
> > Hi!

>
> > `declaration' appears before `statement' within local block in the
> > following diagram. So, does C specify the order of block declaration
> > just by this? Is there other description about the order of block
> > declaration? I can't find it in n1124.pdf.

>
> > <quote>
> > * (6.8.2) block-item:
> > * * declaration
> > * * statement
> > </quote>

>
> > Thank you for your time.

>
> C99 allows mixed code and declarations. All versions of C before C99
> mandated that declarations precede code within a block.


Thank you. I remember that some earlier versions don't allow
declarations in nested block in a function, do they?
 
Reply With Quote
 
santosh
Guest
Posts: n/a
 
      02-08-2008
(E-Mail Removed) wrote:

> On Feb 9, 12:13*am, santosh <(E-Mail Removed)> wrote:
>> (E-Mail Removed) wrote:
>> > Hi!

>>
>> > `declaration' appears before `statement' within local block in the
>> > following diagram. So, does C specify the order of block
>> > declaration just by this? Is there other description about the
>> > order of block declaration? I can't find it in n1124.pdf.

>>
>> > <quote>
>> > (6.8.2) block-item:
>> > declaration
>> > statement
>> > </quote>

>>
>> > Thank you for your time.

>>
>> C99 allows mixed code and declarations. All versions of C before C99
>> mandated that declarations precede code within a block.

>
> Thank you. I remember that some earlier versions don't allow
> declarations in nested block in a function, do they?


As far as I know, all versions of Standard C allow declarations in
nested blocks.

 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      02-08-2008
santosh <(E-Mail Removed)> writes:
[...]
> C99 allows mixed code and declarations. All versions of C before C99
> mandated that declarations precede code within a block.


That declarations precede *statements* in a block. (Declarations are
arguably "code".)

--
Keith Thompson (The_Other_Keith) <(E-Mail Removed)>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Army1987
Guest
Posts: n/a
 
      02-08-2008
Keith Thompson wrote:

> That declarations precede *statements* in a block. (Declarations are
> arguably "code".)


IMO they are, but, for example, gcc says "C90 doesn't allow mixed
declaration and code".
I don't see the point for *that* definition of "code", but...



--
Army1987 (Replace "NOSPAM" with "email")
 
Reply With Quote
 
CJ
Guest
Posts: n/a
 
      02-09-2008
On Feb 8, 2:50 pm, Army1987 <(E-Mail Removed)> wrote:
> Keith Thompson wrote:
> > That declarations precede *statements* in a block. (Declarations are
> > arguably "code".)

>
> IMO they are, but, for example, gcc says "C90 doesn't allow mixed
> declaration and code".
> I don't see the point for *that* definition of "code", but...
>
> --
> Army1987 (Replace "NOSPAM" with "email")


I think gcc is saying syntax such as "for(int ii=0;ii < 1;ii++) ;" is
not allowed, a statement containing a declaration, "int ii."

As for "Declarations are arguably 'code'" in-so-far registers are
assigned values, I can agree. But CPU registers are not "hidden" from
the c programmer. In assembler, declarations are indeed code, IMHO.
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      02-09-2008
CJ <(E-Mail Removed)> writes:
> On Feb 8, 2:50 pm, Army1987 <(E-Mail Removed)> wrote:
>> Keith Thompson wrote:
>> > That declarations precede *statements* in a block. (Declarations are
>> > arguably "code".)

>>
>> IMO they are, but, for example, gcc says "C90 doesn't allow mixed
>> declaration and code".
>> I don't see the point for *that* definition of "code", but...

>
> I think gcc is saying syntax such as "for(int ii=0;ii < 1;ii++) ;" is
> not allowed, a statement containing a declaration, "int ii."
>
> As for "Declarations are arguably 'code'" in-so-far registers are
> assigned values, I can agree. But CPU registers are not "hidden" from
> the c programmer. In assembler, declarations are indeed code, IMHO.


I think you meant to say that CPU registers are hidden from the C
programmer (i.e., you had an extra "not"). But I fail to see what
this has to do with the question of whether declarations are "code".

We're never going to settle this definitively, since there's no formal
definition of the word "code" (at least not in the C standard). But
clearly both declarations and statements can involve the evaluation of
expressions, including function calls, which can result in the
execution of statements. A declaration is executed in much the same
sense that a statement is. (In Ada, for example, the execution of a
declaration is called "elaboration": statements are executed,
declarations are elaborated, and expressions are evaluated.)

Consider:

#include <stdio.h>
int main(void)
{
/* A declaration that performs output: */
int dummy = printf("Hello, world\n");

/* A statement that does nothing: */
;

return 0;
}

I'd call that declaration "code".

It's not a big deal either way, though (<OT>but I'd like to see the
gcc warning "ISO C90 forbids mixed declarations and code" changed to
"ISO C90 forbids mixed declarations and statements"</OT>).

--
Keith Thompson (The_Other_Keith) <(E-Mail Removed)>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Bill Leary
Guest
Posts: n/a
 
      02-10-2008
"Keith Thompson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Consider:
>
> #include <stdio.h>
> int main(void)
> {
> /* A declaration that performs output: */
> int dummy = printf("Hello, world\n");
>
> /* A statement that does nothing: */
> ;
>
> return 0;
> }
>
> I'd call that declaration "code".


I'd always just taken that as another way C let's you be concise.

The line
int dummy = printf("Hello, world\n");

(and it's like) I've been interpreting as

int dummy;
printf("Hello, world\n");

for all these years. That is, I always saw it as a short hand form of a
declaration and code.

- Bill

 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      02-10-2008
"Bill Leary" <(E-Mail Removed)> writes:
> "Keith Thompson" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Consider:
>>
>> #include <stdio.h>
>> int main(void)
>> {
>> /* A declaration that performs output: */
>> int dummy = printf("Hello, world\n");
>>
>> /* A statement that does nothing: */
>> ;
>>
>> return 0;
>> }
>>
>> I'd call that declaration "code".

>
> I'd always just taken that as another way C let's you be concise.


Yes, it's that too.

> The line
> int dummy = printf("Hello, world\n");
>
> (and it's like) I've been interpreting as
>
> int dummy;
> printf("Hello, world\n");
>
> for all these years. That is, I always saw it as a short hand form of
> a declaration and code.


Actually, it's equivalent to:

int dummy;
dummy = printf("Hello, world\n");

The question is what the word "code" means. I see no reason to limit
it to C statements. The real point is that, since there seems to be
no consensus on what the word "code" really means, it's better to use
an unambiguous term. If you want to talk about statements, call them
"statements".

--
Keith Thompson (The_Other_Keith) <(E-Mail Removed)>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fo:Block can you check to see if a block contains any text by using the block id? morrell XML 1 10-10-2006 07:18 PM
maxplusII error: a deferred constant declaration without a full declaration is not supported Noah VHDL 5 04-07-2006 02:34 PM
Function declaration in class declaration Ovidesvideo C++ 4 12-10-2004 06:36 PM
Intel C++ 8.0 : declaration hides declaration Alex Vinokur C++ 4 04-05-2004 09:49 PM



Advertisments