Miles_Prower
December 16th, 2008, 03:14 AM
As the title suggests, I've got a sample program from a book that will not compile.
So, here's the code:
// VariableSize - output the size of each type of
// variable
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int nNumberofArgs, char* pszArgs[])
{
bool b;
char c;
int n;
long l;
float f;
double d;
cout << sizeof a bool = << sizeof b << endl;
cout << sizeof a char = << sizeof c << endl;
cout << sizeof an int = << sizeof n << endl;
cout << sizeof a long = << sizeof l << endl;
cout << sizeof a float = << sizeof f << endl;
cout << sizeof a double= << sizeof d << endl;
// wait until user is ready before terminating program
// to allow the user to see the program results
system(PAUSE);
return 0;
}
, And here's the output I get when I try to compile it:
taels@tornado:~/code$ g++ main.cpp
main.cpp:15: error: stray \342 in program
main.cpp:15: error: stray \200 in program
main.cpp:15: error: stray \234 in program
main.cpp:15: error: stray \342 in program
main.cpp:15: error: stray \200 in program
main.cpp:15: error: stray \234 in program
main.cpp:16: error: stray \342 in program
main.cpp:16: error: stray \200 in program
main.cpp:16: error: stray \234 in program
main.cpp:16: error: stray \342 in program
main.cpp:16: error: stray \200 in program
main.cpp:16: error: stray \234 in program
main.cpp:17: error: stray \342 in program
main.cpp:17: error: stray \200 in program
main.cpp:17: error: stray \234 in program
main.cpp:17: error: stray \342 in program
main.cpp:17: error: stray \200 in program
main.cpp:17: error: stray \234 in program
main.cpp:18: error: stray \342 in program
main.cpp:18: error: stray \200 in program
main.cpp:18: error: stray \234 in program
main.cpp:18: error: stray \342 in program
main.cpp:18: error: stray \200 in program
main.cpp:18: error: stray \234 in program
main.cpp:19: error: stray \342 in program
main.cpp:19: error: stray \200 in program
main.cpp:19: error: stray \234 in program
main.cpp:19: error: stray \342 in program
main.cpp:19: error: stray \200 in program
main.cpp:19: error: stray \234 in program
main.cpp:20: error: stray \342 in program
main.cpp:20: error: stray \200 in program
main.cpp:20: error: stray \234 in program
main.cpp:20: error: stray \342 in program
main.cpp:20: error: stray \200 in program
main.cpp:20: error: stray \234 in program
main.cpp:23: error: stray \342 in program
main.cpp:23: error: stray \200 in program
main.cpp:23: error: stray \234 in program
main.cpp:23: error: stray \342 in program
main.cpp:23: error: stray \200 in program
main.cpp:23: error: stray \235 in program
main.cpp: In function int main(int, char**):
main.cpp:15: error: a was not declared in this scope
main.cpp:15: error: expected `;' before bool
main.cpp:16: error: expected `;' before char
main.cpp:17: error: an was not declared in this scope
main.cpp:17: error: expected `;' before int
main.cpp:18: error: expected `;' before long
main.cpp:19: error: expected `;' before float
main.cpp:20: error: expected `;' before double
main.cpp:23: error: PAUSE was not declared in this scope
taels@tornado:~/code$
I'm not familiar with the (stray \235) variety of error, and this is supposed to be an example of FUNCTIONAL code, but I can't help but think this kind of thing would have been caught before it was published...
Could someone who has experience with pointers tell me who's at fault, me or the book?
So, here's the code:
// VariableSize - output the size of each type of
// variable
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int nNumberofArgs, char* pszArgs[])
{
bool b;
char c;
int n;
long l;
float f;
double d;
cout << sizeof a bool = << sizeof b << endl;
cout << sizeof a char = << sizeof c << endl;
cout << sizeof an int = << sizeof n << endl;
cout << sizeof a long = << sizeof l << endl;
cout << sizeof a float = << sizeof f << endl;
cout << sizeof a double= << sizeof d << endl;
// wait until user is ready before terminating program
// to allow the user to see the program results
system(PAUSE);
return 0;
}
, And here's the output I get when I try to compile it:
taels@tornado:~/code$ g++ main.cpp
main.cpp:15: error: stray \342 in program
main.cpp:15: error: stray \200 in program
main.cpp:15: error: stray \234 in program
main.cpp:15: error: stray \342 in program
main.cpp:15: error: stray \200 in program
main.cpp:15: error: stray \234 in program
main.cpp:16: error: stray \342 in program
main.cpp:16: error: stray \200 in program
main.cpp:16: error: stray \234 in program
main.cpp:16: error: stray \342 in program
main.cpp:16: error: stray \200 in program
main.cpp:16: error: stray \234 in program
main.cpp:17: error: stray \342 in program
main.cpp:17: error: stray \200 in program
main.cpp:17: error: stray \234 in program
main.cpp:17: error: stray \342 in program
main.cpp:17: error: stray \200 in program
main.cpp:17: error: stray \234 in program
main.cpp:18: error: stray \342 in program
main.cpp:18: error: stray \200 in program
main.cpp:18: error: stray \234 in program
main.cpp:18: error: stray \342 in program
main.cpp:18: error: stray \200 in program
main.cpp:18: error: stray \234 in program
main.cpp:19: error: stray \342 in program
main.cpp:19: error: stray \200 in program
main.cpp:19: error: stray \234 in program
main.cpp:19: error: stray \342 in program
main.cpp:19: error: stray \200 in program
main.cpp:19: error: stray \234 in program
main.cpp:20: error: stray \342 in program
main.cpp:20: error: stray \200 in program
main.cpp:20: error: stray \234 in program
main.cpp:20: error: stray \342 in program
main.cpp:20: error: stray \200 in program
main.cpp:20: error: stray \234 in program
main.cpp:23: error: stray \342 in program
main.cpp:23: error: stray \200 in program
main.cpp:23: error: stray \234 in program
main.cpp:23: error: stray \342 in program
main.cpp:23: error: stray \200 in program
main.cpp:23: error: stray \235 in program
main.cpp: In function int main(int, char**):
main.cpp:15: error: a was not declared in this scope
main.cpp:15: error: expected `;' before bool
main.cpp:16: error: expected `;' before char
main.cpp:17: error: an was not declared in this scope
main.cpp:17: error: expected `;' before int
main.cpp:18: error: expected `;' before long
main.cpp:19: error: expected `;' before float
main.cpp:20: error: expected `;' before double
main.cpp:23: error: PAUSE was not declared in this scope
taels@tornado:~/code$
I'm not familiar with the (stray \235) variety of error, and this is supposed to be an example of FUNCTIONAL code, but I can't help but think this kind of thing would have been caught before it was published...
Could someone who has experience with pointers tell me who's at fault, me or the book?