473,698 Members | 2,398 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Weird Output

Hi,
When I compiles the following program with g++, it gives the following
output:

[root@localhost C++]# g++ -o list list.C
list.C: In function `int main()':
list.C:116: jump to case label
list.C:110: crosses initialization of `std::string data'
list.C:120: jump to case label
list.C:110: crosses initialization of `std::string data'
Internal compiler error: Error reporting routines re-entered.
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://bugzilla.redhat .com/bugzilla/> for instructions.
[root@localhost C++]#

However, if I changes the template type to int in the statement
LinkedList<stri ng> list( i.e. to change the statement to
LinkedList<int> list;),
then then program compiles properly. Can anybody help to sort out the
error.

Here is the complete program:

using namespace std;
#include <iostream>
#include <string>

template <class T>
class ListElement
{
public:
ListElement(Lis tElement<T> *,T );
T const & Data() const;
ListElement<T> ** Next() ;

private:

ListElement<T> *next;
T data;
};

template <class T>
class LinkedList
{
public:
LinkedList();
void display();
void Append(T item);
private:
ListElement<T> *Head, *Tail;
};

// Implementing the various functions of the ListElement class.
template <class T>
ListElement<T>: : ListElement(Lis tElement<T> * _next, T _data):
data(_data),nex t(_next)
{
}

template <class T>
T const & ListElement<T>: : Data() const
{
return data;
}

template <class T>
ListElement<T> ** ListElement<T>: : Next()
{
return &next;
}

// ListElement class functions implemented.

//Implementing the various functions of the LinkedList class.

template <class T>
void LinkedList<T>:: display()
{
ListElement<T> *tmp;
tmp=Head;
if(Head == NULL)
{
cout<<"No elements in the List\n";
return;
}

while(tmp!=NULL )
{
cout<< tmp->Data() << "\n";
tmp=*tmp->Next();
}
return ;
}

template <class T>
LinkedList<T>:: LinkedList()
:Head(NULL), Tail( NULL)
{
}

template <class T>
void LinkedList<T>:: Append (T item)
{
ListElement<T> *tmp;
tmp = new ListElement<T>( NULL, item);

if(Head == NULL){
Head = Tail = tmp;
return ;
}
*Tail->Next() = tmp;
Tail = tmp;
return;
}
LinkedList<stri ng> list;

int main(void)
{

// LinkedList<stri ng> list;
int choice;
cout<<"1: Display\n2: Prepend\n3: Exit\n ";
cin>>choice;
switch(choice)
{
case 1:
list.display();
break;

case 2:
string data;
cout<<"enter the data to be added to the list\n";
cin>>data;
list.Append(dat a);
break;

case 3:
exit(1);
break;

default:
cout<<"Invalid Choice\n";
break;

}

main();
return 0;
}


Sep 29 '05 #1
2 6769
alice wrote:
Hi,
When I compiles the following program with g++, it gives the following
output:

[root@localhost C++]# g++ -o list list.C
list.C: In function `int main()':
list.C:116: jump to case label
list.C:110: crosses initialization of `std::string data'
list.C:120: jump to case label
list.C:110: crosses initialization of `std::string data'
Internal compiler error: Error reporting routines re-entered.
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://bugzilla.redhat .com/bugzilla/> for instructions.
[root@localhost C++]#

However, if I changes the template type to int in the statement
LinkedList<stri ng> list( i.e. to change the statement to
LinkedList<int> list;),
then then program compiles properly. Can anybody help to sort out the
error.
int main(void)
{

// LinkedList<stri ng> list;
int choice;
cout<<"1: Display\n2: Prepend\n3: Exit\n ";
cin>>choice;
switch(choice)
{
case 1:
list.display();
break;

case 2:
string data;
cout<<"enter the data to be added to the list\n";
cin>>data;
list.Append(dat a);
break;

case 3:
exit(1);
break;

default:
cout<<"Invalid Choice\n";
break;


Imagine the program has reached this point. Now does the compiler
destroy the string variable 'data' or not? If you got here via case 1, 3
or default then no, but if you got here via case 2 then yes. This kind
of this is too much for the compiler to keep track of so it is forbidden.

Change case 2 to this

case 2:
{
string data;
cout<<"enter the data to be added to the list\n";
cin>>data;
list.Append(dat a);
}
break;

Now only case 2 uses the data variable and the problem goes away.

john
Sep 29 '05 #2

"alice" <al***********@ yahoo.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
Hi,
When I compiles the following program with g++, it gives the following
output:

[root@localhost C++]# g++ -o list list.C
list.C: In function `int main()':
list.C:116: jump to case label
list.C:110: crosses initialization of `std::string data'
list.C:120: jump to case label
list.C:110: crosses initialization of `std::string data'
My Visual C++ documentation sums up the problem fairly well:
=============== =============== =============== =============== =============
Compiler Error C2360
initialization of 'identifier' is skipped by 'case' label

The specified identifier initialization can be skipped in a switch
statement.

It is illegal to jump past a declaration with an initializer unless the
declaration is enclosed in a block.

The scope of the initialized variable lasts until the end of the switch
statement unless it is declared in an enclosed block within the switch
statement.

The following is an example of this error:

void func( void )
{
int x;
switch ( x )
{
case 0 :
int i = 1; // error, skipped by case 1
{ int j = 1; } // OK, initialized in enclosing block
case 1 :
int k = 1; // OK, initialization not skipped
}
}

=============== =============== =============== =============== =============

Though it's not explicit in the code, the std::string object
does have an implicit initializer. (I.e. it's not possible
(by design) to define a string object without initializing
it -- lack of a specific initializer causes an empty string
to be created.

It works with 'int' because an 'int' object can be created
without initializing it (but I always recommend against doing that).


Internal compiler error: Error reporting routines re-entered.
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://bugzilla.redhat .com/bugzilla/> for instructions.
[root@localhost C++]#
Don't be concerned with this error unless it still occurs
after all the other errors have been fixed.

However, if I changes the template type to int in the statement
LinkedList<stri ng> list( i.e. to change the statement to
LinkedList<int> list;),
then then program compiles properly. Can anybody help to sort out the
error.

Here is the complete program:

using namespace std;
You need to move this line to after the #include
directives. At this point there's no namespace 'std'.
#include <iostream>
#include <string>
using namespace std;
[snip] switch(choice)
{
case 1:
list.display();
break;

case 2:
string data;
cout<<"enter the data to be added to the list\n";
cin>>data;
list.Append(dat a);
break;

case 3:
exit(1);
break;

default:
cout<<"Invalid Choice\n";
break;

}

main();
What is this for? It appears to be an attempt to have
'main()' call itself (recursion, and with no way to
terminate the recursion). Also, AFAIK, it's not legal
for 'main()' to call itself in C++.
return 0;
}


-Mike

Sep 29 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1684
by: redneck_kiwi | last post by:
All: I have an application that has been working well for 3-4 months now without any issues (that I am aware of). A day or two ago, one of our employees that use this application called to say she was getting a weird message: "Warning: Cannot modify header information - headers already sent by (output started at /www/htdocs/sys36/viewhist.php:2) in /www/htdocs/sys36/viewhist.php on line 5"
7
4753
by: Yamin | last post by:
I found some code that seems a bit weird and is refusing to compile on GCC...it apparently used to compile fine on other comilers. typedef void ASY_TESTPROC_T __((OIDC_T lastmatch, int compc, OIDC_T *compl, ....)); There are several other ASY_XXXX defintion following, but AST_TESTPROC_T is the first one. There is macro: __(x) defined which basically does this
10
2055
by: Chris Mantoulidis | last post by:
I see some really weird output from this program (compiled with GCC 3.3.2 under Linux). #include <iostream> using namespace std; int main() { char *s; s = "test1"; cout << "s = " << s << " and &s = " << &s << "\n";
1
1999
by: Chris Mantoulidis | last post by:
PROBLEM: I'm having some weird problems with string::find() (in ParamGenerate()), but since I'm not sure if that is the source of all bad output in my program, I'm posting least code that's compilable. OTHER INFO: Just so you know what the program does (and so you can give it some input to test it), at this stage I want it to break the input into some parts. Here is the input style: <middle param> <middle param> ...... <middle param>...
11
13706
by: Les Paul | last post by:
I'm trying to design an HTML page that can edit itself. In essence, it's just like a Wiki page, but my own very simple version. It's a page full of plain old HTML content, and then at the bottom, there's an "Edit" link. So the page itself looks something like this: <HTML><HEAD><TITLE>blah</TITLE></HEAD><BODY> <!-- TEXT STARTS HERE --> <H1>Hello World!</H1> <P>More stuff here...</P>
10
1845
by: Bonj | last post by:
Hello. I hope somebody can help me on this, because I'm running out of options to turn to. I have almost solved my regular expression function. Basically it works OK if unicode is defined. It doesn't work OK in ANSI mode however, as it has to use MultiByteToWideChar and WideCharToMultiByte. I've discovered that the regular expression part is working fine. As far as I can tell the regular expression code is correctly parsing what it...
5
2366
by: Jim Strathmeyer | last post by:
So I'm having some weird problems with file output. If I try to boil this problem down to a small, simple program to just show what problems I'm having, I can't get the same problematic behavior. I have a function: bool Tourist::CreateMaps() { debug.Out() << "Tourist::CreateMaps" << std::endl; std::ofstream out((player_name + ".sav").c_str(),std::ios::out); std::string ms = Random::MapStart();
0
1345
by: spacelabstudio | last post by:
Hi, I'm observing some weird behavior and have written the following test program to demonstrate. This works under cygwin/WinXP but not Gentoo(kernel 2.6): huh.py ------------------------------------------- import pty,os,sys # Fork ( pid, fd ) = pty.fork()
5
1710
by: Pupeno | last post by:
Hello, I am experiencing a weird behavior that is driving me crazy. I have module called Sensors containing, among other things: class Manager: def getStatus(self): print "getStatus(self=%s)" % self return {"a": "b", "c": "d"} and then I have another module called SensorSingleton that emulates the
10
2158
by: alsmeirelles | last post by:
Hi all, I Have run this test: Private Sub test() Dim d As Double Dim f As Single Dim output As String d = 8888888888888.8887
0
8678
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9166
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9030
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8871
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4621
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2333
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.