![]() |
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 |
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 |
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.