Function and variable declarations

K

Keith Thompson

pemo said:
Flash Gordon said:
pemo wrote:

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:

main()
{
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.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top