From: Leo Davidson on
On May 9, 3:07 am, "Leslie Milburn" <CD...(a)NOSPAM.bigpond.com> wrote:

> Personally this is a feature of C++ I have never liked.

I'm guessing that you don't use RAII much. :-)

http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization
From: Leslie Milburn on

"Leo Davidson" <leonudeldavidson(a)googlemail.com> wrote:
> I'm guessing that you don't use RAII much. :-)
> http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization

You would be correct - then again I don't rely upon exceptions to cleanup. I
prefer my programs not to fail, and they rarely do :-)

But to be honest, I prefer C to C++ and you do learn how to write very
robust code. Mind you, I am liking the simplicity of C# also in preference
to C++. I feel that it is a much better successor to C.



From: Ulrich Eckhardt on
Leslie Milburn wrote:
> Does this imply that new C compilers allow variable declaration anywhere ?
> I haven't tried it myself but I'm just wondering.

Even some older ones allow it. However, the C89 standard forbids it, while
the C99 standard allows it.

Uli

--
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

From: Michael Wojcik on
ScottMcP [MVP] wrote:
> On May 8, 1:59 pm, blaster2 <kstai...(a)iit.edu> wrote:
>> I keep writing this program to model populations and it keeps giving
>> me an error "Declaration is not allowed here in function main"
>
> At a guess, you are compiling the code as C instead of C++.

The real question is what language the OP is writing in. It appears to
be either C or C++, but those are different languages. The source
should, of course, be compiled with a compiler for the proper
language, whatever it might be.

> Old C
> compilers require you to declare all local variables before a
> function's code begins.

As of the first C standard, block-scope variables in C can be declared
at the beginning of any block, not just the beginning of a function.
The essence of your point, though, is correct: The code provided by
the OP has declarations that are not at the beginning of a block, so
that's probably the cause of the error.

C99 permits declarations after non-declaration statements, not just at
the beginning of a block. But many C implementations do not support
the C99 specification, or support only parts of it.

--
Michael Wojcik
Micro Focus
Rhetoric & Writing, Michigan State University