D&C Lug - Home Page
Devon & Cornwall Linux Users' Group

[ Date Index ][ Thread Index ]
[ <= Previous by date / thread ] [ Next by date / thread => ]

Re: [LUG] A programming problem



On Wed, 2003-05-07 at 21:26, Tom Glare wrote:
> Are there any Charlie Double Plus programmers who could explain this
> little conundrum to me ?
> 
> When I compile the following programme
> 
> ===
> 
> int main() {
>    int * a = new int;
>    int b;
>    switch (b) {
>       case 0 :
>          int * c = new int;
>          // int * c;                  Compiles sucessfully
>          // c = new int;              if I do it this way
>          break;
>       case 1 :
>          int * d = new int;
>          break;
>    }
>    return 0;
> }
> ===
> - I get the following error :
> ===
> 
> test.cpp: In function `int main ()':
> test.cpp:10: jump to case label
> test.cpp:6:   crosses initialization of `int *c'
> 
> ===
> 
> Am relatively new to the wonderful world of C++, so is probably something
> elementary I am getting wrong.
> 

When I use g++ test.cpp, an a.out gets compiled for both of the program
versions.

When I use gcc test.cpp, things go a little odd + create the results you
report, I may be wrong but I would say you are compiling C++ with a
confused compiler ?

As a matter of interest, are you going to initialise the value for b?  I
assume that you have used this simple case as an example of your
problem.

> 
> As an quick aside - and note that I am only adding this to an eMail that I
> was going to send anyway, so excuse myself from blacking the kettle - I
> would like to say that I hope Ray (Smith) is not put off the LUG by the
> rudeness of one or two subscribers. I certainly do not mind the occasional
> eMail that is possibly misplaced but certainly well intentioned, but I do
> not like to read the public whinings of those who could have easily just
> made a gentle suggestion in a private eMail to Ray. Any complaints about
> my view, please complain to me, not to the list, unless you really want to
> prove my point for me.
> 

Yup, this really upsets me too.  Live and let live dudes.

James.

> 
> Regards to all, Tom.



--
The Mailing List for the Devon & Cornwall LUG
Mail majordomo@xxxxxxxxxxxx with "unsubscribe list" in the
message body to unsubscribe.


Lynx friendly