Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Function and variable declarations

Thread Tools

Function and variable declarations

Keith Thompson
Posts: n/a
"pemo" <(E-Mail Removed)> writes:
> "Flash Gordon" <(E-Mail Removed)> wrote in message
> news(E-Mail Removed)
>> pemo wrote:
>> <snip>
>>> I'm still a bit 'old school' I'm afraid, and typically declare my
>>> variables at the top of a function - no matter where they're used in that
>>> function.
>>> Many years ago, I would have loved having some mechanism that allowed me
>>> to declare them 'nearer' to where they were used - but, then, C wouldn't
>>> allow that. Nowadays, [being an 'old dog' that can't learn 'new tricks']
>>> I stick

>> Must be very old school, since it is allowed by C89.

> Um, let's see - can't remember exactly when I started, but it was around
> 1980 [and I used to be quite good at it then I believe]

Ok, that's pre-ANSI, but I think it's post-K&R1.

As far as I know, the following was legal even back then:

int function_scope_var;
int block_scope_var;
int another_block_scope_var;

Were you using a compiler that didn't allow it?

(Of course mixing declarations and statements wasn't allowed until C99.)

Keith Thompson (The_Other_Keith) Removed) <>
San Diego Supercomputer Center <*> <>
We must do something. This is something. Therefore, we must do this.
Reply With Quote

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
Variable argument function as a parameter of a variable argument function AikidoGuy C Programming 11 11-21-2011 10:43 PM
Variable declarations TCB ASP .Net 3 03-21-2006 07:18 PM
member variable declaration and forward declarations John Ratliff C++ 2 08-26-2005 07:50 PM
Visual Studio forgets about variable declarations Nick Stansbury ASP .Net 2 04-11-2005 10:21 AM
function declarations, global/within a function? Douglas C Programming 2 07-05-2004 08:54 PM