# I "Confused" My Compiler!?

This topic is 4277 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Wow. :| Well I'm sure this has to do with strings and pointers. I probably tried to print by address or something wrong. Anyway...get this error: "/stddef.h:153: confused by earlier errors, bailing out" My compiler bailed on me! :D Seriously though, this is strange. It told me all the errors are in stddef.h. What could I have possibly done that would've caused that?

##### Share on other sites
Care to list the other errors? If it tells you that there are so many errors, it can't even look for any more, maybe you should worry about those. If the error is in seperate file, there are a couple things that could have happened. Check before you include the file for any missing semicolons or other syntax errors. Also, are you sure you didn't accidentally change anything with the file?

##### Share on other sites
Quote:
 Original post by Sr_GuapoCare to list the other errors? If it tells you that there are so many errors, it can't even look for any more, maybe you should worry about those. If the error is in seperate file, there are a couple things that could have happened. Check before you include the file for any missing semicolons or other syntax errors. Also, are you sure you didn't accidentally change anything with the file?

Yeah sure...here's the complete listing:

[SOURCE]C:\Documents and Settings\(MY NAME)\My Documents\Assignment 6>g++ -c PrintData.cppIn file included from PrintData.cpp:1:stocks.h:47:7: warning: no newline at end of fileIn file included from C:/Documents and Settings/(MY NAME)/My Documents/School/(MY SCHOOL)/11th Grade/Quarter 2/Intro to C/MinGW/include/c++/3.2.3/iosfwd:45,                 from C:/Documents and Settings/(MY NAME)/My Documents/School/(MY SCHOOL)/11th Grade/Quarter 2/Intro to C/MinGW/include/c++/3.2.3/ios:44,                 from C:/Documents and Settings/(MY NAME)/My Documents/School/(MY SCHOOL)/11th Grade/Quarter 2/Intro to C/MinGW/include/c++/3.2.3/ostream:45,                 from C:/Documents and Settings/(MY NAME)/My Documents/School/(MY SCHOOL)/11th Grade/Quarter 2/Intro to C/MinGW/include/c++/3.2.3/iostream:45,                 from PrintData.cpp:2:C:/Documents and Settings/(MY NAME)/My Documents/School/(MY SCHOOL)/11th Grade/Quarter 2/Intro to C/MinGW/include/c++/3.2.3/bits/stringfwd.h: In   function char* GetMonth(int)':C:/Documents and Settings/(MY NAME)/My Documents/School/(MY SCHOOL)/11th Grade/Quarter 2/Intro to C/MinGW/include/c++/3.2.3/bits/stringfwd.h:46: parse   error before namespace'C:/Documents and Settings/(MY NAME)/My Documents/School/(MY SCHOOL)/11th Grade/Quarter 2/Intro to C/MinGW/include/c++/3.2.3/bits/stringfwd.h:54: parse   error before <' tokenC:/Documents and Settings/(MY NAME)/My Documents/School/(MY SCHOOL)/11th Grade/Quarter 2/Intro to C/MinGW/include/c++/3.2.3/bits/stringfwd.h:58: explicit   specialization in non-namespace scope char* GetMonth(int)'C:/Documents and Settings/(MY NAME)/My Documents/School/(MY SCHOOL)/11th Grade/Quarter 2/Intro to C/MinGW/include/c++/3.2.3/bits/stringfwd.h:58:    char_traits' is not a templateC:/Documents and Settings/(MY NAME)/My Documents/School/(MY SCHOOL)/11th Grade/Quarter 2/Intro to C/MinGW/include/c++/3.2.3/bits/stringfwd.h:60: syntax   error before ;' tokenC:/Documents and Settings/(MY NAME)/My Documents/School/(MY SCHOOL)/11th Grade/Quarter 2/Intro to C/MinGW/lib/gcc-lib/mingw32/3.2.3/include/stddef.h:153: confused by earlier errors, bailing out[/SOURCE]

##### Share on other sites
Maybe if you could post your code, it may make a bit more sense. It looks like this is a homework assignment, so we can't really just tell you the answer, but we can definately help point you in the correct direction!

##### Share on other sites
Try posting where you include cstddef (or whatever includes it) and the code right before it.

##### Share on other sites
Quote:
 Original post by Sr_GuapoMaybe if you could post your code, it may make a bit more sense. It looks like this is a homework assignment, so we can't really just tell you the answer, but we can definately help point you in the correct direction!

Ah don't worry. It was a homework assignment, but I gave up on it because my approach was way off. (it's only like 1% of my grade and it's due tommorow, the last day of class, anyway)

But sure..you can look at the code. Like I said though, I'm pretty sure it's a string problem. My teacher never taught us to use C++ strings, just character arrays.

[SOURCE]#include "stocks.h"#include <iostream>void PrintData(struct stock &x){	int i = 0;	for(;;)	{		cout << "                                " // CENTERING			 << x.symbol << ':' << GetYear(i);		for(;;)		{			if( (i-1)%372 = 0) break;		    cout << "\n" << GetMonth(i) 			     << "        "				 << "*-----Open----* *-----High----*"				 << "*----Low ----* *----Close----* "				 << "          "				 << "Max     Min     Max     Min"				 << "     Max    Min     Max     Min"				 << endl;					}		}}int GetYear(int i) { if(i < 372) return 2004; else return 2005;}char * GetMonth(int i){	float j = (i-1)/31;	if(j < 1) return "Jan.";	if(j < 2) return "Feb.";	if(j < 3) return "Mar.";	if(j < 4) return "Apr.";	if(j < 5) return "May.";	if(j < 6) return "Jun.";	if(j < 7) return "Jul.";	if(j < 8) return "Aug.";	if(j < 9) return "Sep.";	if(j < 10)return "Oct.";	if(j < 11)return "Nov.";	if(j < 12)return "Dec.";	if(j < 13)return "Jan.";	if(j < 14)return "Feb.";	if(j < 15)return "Mar.";	if(j < 16)return "Apr.";	if(j < 17)return "May.";	if(j < 18)return "Jun.";	if(j < 19)return "Jul.";	if(j < 20)return "Aug.";	if(j < 21)return "Sep.";	if(j < 22)return "Oct.";	if(j < 23)return "Nov.";	else      return "Dec.";}[/SOURCE]

##### Share on other sites
EDIT: Nevermind.

That's some ugly code. The use of char* for strings in C++ is, as you mentioned, particularly nasty. The most obvious think I see is that you need to qualify objects in the std namespace (std::cout) or insert a "using std::cout" or "using namespace std" near the top someplace. Unless stocks.h has it... but that would be evil as well.

Use std::string unless your teacher/professor has explicitly forbid it (or explicitly required char*... in which case change the return type of GetMonth() to const char* at least).

##### Share on other sites
Quote:
 Original post by CTarTry posting where you include cstddef (or whatever includes it) and the code right before it.

But i don't. :| I just included iostream and my own header file.

##### Share on other sites
What does your header file look like?

##### Share on other sites
For a start - put some newlines at the end of your "stocks.h" file.
Unlike Visual C++, gcc has some problems if there is no newline symbols at the end of included header file (had some problems with this issue myself).

EDIT: you don't have any 'using' statements, but you use cout and endl as if they are not in std namespace - either you didn't post all code, or you missed it.

##### Share on other sites
Quote:
 Original post by jpetrieEDIT: Nevermind.That's some ugly code. The use of char* for strings in C++ is, as you mentioned, particularly nasty. The most obvious think I see is that you need to qualify objects in the std namespace (std::cout) or insert a "using std::cout" or "using namespace std" near the top someplace. Unless stocks.h has it... but that would be evil as well.Use std::string unless your teacher/professor has explicitly forbid it (or explicitly required char*... in which case change the return type of GetMonth() to const char* at least).

Yeah...I really had this one messed up, which is why I'm not even gonna attempt to get it done in time for tommorow. I was just wondering why all the errors were happening in this header file, and why I "confused" my compiler to the point that it "bailed" on me.

##### Share on other sites
Quote:
 Original post by Paulius MaruskaFor a start - put some newlines at the end of your "stocks.h" file.Unlike Visual C++, gcc has some problems if there is no newline symbols at the end of included header file (had some problems with this issue myself).

Meh..I usually just ignore that little bit. It's just a warning and doesn't really change the compilation. Just a bit more to read while debugging.

##### Share on other sites
Quote:
 Original post by jpetrieWhat does your header file look like?

Like this: (YES I KNOW, REALLY HORRIBLE CODING!)

[SOURCE]#ifndef STOCKS_H#define STOCKS_Hstruct stock{	char symbol[5];	struct Data	{		float open;		float high;		float low;		float close;	} data[744]; //31 Slots Per Month};struct date {int day, month, year;};int SymCheck(char * sym);    /* Pre-Conditions:	 *  Needs 5-Digit Stock Symbol	 *	 * Post-Conditions:	 *  Returns 1 if symbol doesn't work	 *  Returns 0 if symbol does work	 */struct stock & LoadData(char * sym, struct stock &x);	/* Pre-Conditions:	 *   Needs 4-Digit Stock Symbol	 *   Needs Reference to stock struct	 *	 * Post-Conditions:	 *   Returns reference to created struct	 */int DateConv(struct date & d);	/* Pre-Conditions:	 *  Date Struct to convert	 *	 * Post-Conditions:	 *  Returns pos. in array for stock data	 */void PrintData(struct stock &);char * GetMonth(int i)#endif[/SOURCE]

##### Share on other sites
you are missing a semicolon on this line:

char * GetMonth(int i)

##### Share on other sites
Quote:
 Original post by Sr_Guapoyou are missing a semicolon on this line:char * GetMonth(int i)

Heh..guess so. Don't know why that'd give me those errors though.

##### Share on other sites
Quote:
Original post by BringBackFuturama
Quote:
 Original post by Sr_Guapoyou are missing a semicolon on this line:char * GetMonth(int i)

Heh..guess so. Don't know why that'd give me those errors though.

It thinks that it is the start of the function, rather than a prototype. The next lines it found were inside of some header file. You cannot create a namespace inside of a function, so it threw some errors.

##### Share on other sites
Bingo.

To the OP: the reason the errors appear to original in some headers you don't yourself include (such as cstddef) is because your header (which was missing the semicolon) was included before you include <iostream>. Since #include is just a textual substitution, and iostream probably includes some files itself (such as cstddef, eventually) the first errors the compiler sees appear to be in files that are not yours. If you had switched the include order, you might have had a an easier time tracking the mistake down.

Is this a C course or a C++ course, by the way? Because your mixing styles from both languages... which is generally bad, because they are very different languages dispite the apparent level of syntactic similarity.

##### Share on other sites
Quote:
 Original post by jpetrieBingo.To the OP: the reason the errors appear to original in some headers you don't yourself include (such as cstddef) is because your header (which was missing the semicolon) was included before you include . Since #include is just a textual substitution, and iostream probably includes some files itself (such as cstddef, eventually) the first errors the compiler sees appear to be in files that are not yours. If you had switched the include order, you might have had a an easier time tracking the mistake down.Is this a C course or a C++ course, by the way? Because your mixing styles from both languages... which is generally bad, because they are very different languages dispite the apparent level of syntactic similarity.

Ya..I get that now. Thanks...I'll keep that in mind in the future.

And my class is C++, but it's from a teacher who really likes C, so he tries to teach with a lot of C using C++. I'm gonna have to learn strings on my own.

##### Share on other sites
Quote:
 Original post by BringBackFuturamaAnd my class is C++, but it's from a teacher who really likes C, so he tries to teach with a lot of C using C++. I'm gonna have to learn strings on my own.

Get out ASAP (if it is indeed possible). Proper, modern C++ is a different language.

Anyway, I include library headers first and then my own headers; then if something like this happens, the errors at least get reported against my own code, even if it's the "wrong" file.

##### Share on other sites
Quote:
Original post by Zahlman
Quote:
 Original post by BringBackFuturamaAnd my class is C++, but it's from a teacher who really likes C, so he tries to teach with a lot of C using C++. I'm gonna have to learn strings on my own.

Get out ASAP (if it is indeed possible). Proper, modern C++ is a different language.

Anyway, I include library headers first and then my own headers; then if something like this happens, the errors at least get reported against my own code, even if it's the "wrong" file.

hell yah it is. I learned c before I learned c++ and everything you learn from c you pretty much had to throw out the window. the only thing you really carry over is datatypes. most of the algorithms are don't completely differently because of use of containers and overloaded operators, not to mention classes.

##### Share on other sites
Quote:
 Get out ASAP (if it is indeed possible). Proper, modern C++ is a different language.

Tomorrow is his last day of class. Is that ASAP enough? :)

Though I agree. One of the most dangerous things about C++ is that most C code will compile with it, giving it the illusion of being just "an addon". A person should approach writing a C++ program very differently then they would approach a C program, or you're missing much of the improvement that C++ provides.