I "Confused" My Compiler!?

Started by
19 comments, last by JBourrie 17 years, 10 months ago
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?
Originality is dead.
Advertisement
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?
Sean Henley [C++ Tutor]Rensselaer Polytechnic Institute
Quote:Original post by Sr_Guapo
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?


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]

Originality is dead.
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!
Sean Henley [C++ Tutor]Rensselaer Polytechnic Institute
Try posting where you include cstddef (or whatever includes it) and the code right before it.
Quote:Original post by Sr_Guapo
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!


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]

Originality is dead.
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).
Quote:Original post by CTar
Try 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.

Originality is dead.
What does your header file look like?
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.

This topic is closed to new replies.

Advertisement