Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   Coding statements before declaration-a doubt on standard!!! (http://www.velocityreviews.com/forums/t435164-coding-statements-before-declaration-a-doubt-on-standard.html)

s.subbarayan 09-10-2004 06:24 AM

Coding statements before declaration-a doubt on standard!!!
 
Dear all,
Whats the notion behind C standard preventing declaration in middle
of statements?While C++ allows this will it not be good if this
supported in C also?
Also theres some point if we refer to some variable which is not
declared so preventing of in between declarations can be supported.But
what if i simply want to do printf "hello world" in between
declarations?
expecting wishful thoughts from beautiful minds,
Regards,
s.subbarayan

Richard Bos 09-10-2004 07:40 AM

Re: Coding statements before declaration-a doubt on standard!!!
 
s_subbarayan@rediffmail.com (s.subbarayan) wrote:

> Whats the notion behind C standard preventing declaration in middle
> of statements?


It can often be easier to maintain. You don't have to go looking through
all your code to find a declaration; you know it will be in one of a
limited number of places, usually at the top of the current function or
in a header.

> While C++ allows this will it not be good if this supported in C also?


As of C99, it _is_ supported. I'm not completely sure this was a good
idea, either.

> Also theres some point if we refer to some variable which is not
> declared so preventing of in between declarations can be supported.


I'm sorry, but I couldn't parse that sentence.

> But what if i simply want to do printf "hello world" in between
> declarations?


Why would you want to do that?

Richard

Kelsey Bjarnason 09-10-2004 11:28 AM

Re: Coding statements before declaration-a doubt on standard!!!
 
[snips]

On Fri, 10 Sep 2004 07:40:06 +0000, Richard Bos wrote:

> s_subbarayan@rediffmail.com (s.subbarayan) wrote:
>
>> Whats the notion behind C standard preventing declaration in middle
>> of statements?


> As of C99, it _is_ supported. I'm not completely sure this was a good
> idea, either.


Actually, I really like this feature. While it does mean variable
definitions are scattered about, it also means that they tend to be
(or at least, _should_ tend to be) more closely linked to the code that
uses them:

void func(void)
{
int i;
/* 20 lines of code */
i = init();
use(i);
}

vs

void func(void)
{
/* 20 lines of code */
int i = init();
use(i);
}

Matter of preference, perhaps, and you can "fake it" using block scoping,
but I find this approach, on the whole, cleaner than the traditional C
approach.




All times are GMT. The time now is 05:37 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57