Unix Programming - Preprocessor commands?

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > October 2007 > Preprocessor commands?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Preprocessor commands?
desktop

2007-10-02, 7:33 am

I have this in a c++ file:

#ifdef bob
std::cout << "Bob is on\n" << endl;
#else
std::cout << "Bob is off\n" << endl;
#endif


But when compiling I get:

error: expected constructor, destructor, or type conversion before ‘<<’
token

What is wrong with the above code?
Maurizio Loreti

2007-10-02, 7:33 am

desktop <fff@sss.com> writes:

> I have this in a c++ file:
>
> #ifdef bob
> std::cout << "Bob is on\n" << endl;
> #else
> std::cout << "Bob is off\n" << endl;
> #endif
>
> ...
>
> What is wrong with the above code?


you should use std::endl ... I assume you #include <iostream> and
<ostream> , BTW

--
| Maurizio Loreti -- ROT13:ybergv@cq.vasa.vg | (@_
| Un. of Padova, Dept. of Physics, Padova, Italy | //\
| http://www.pd.infn.it/~loreti/mlo.html | V_/_
desktop

2007-10-02, 7:33 am

Maurizio Loreti wrote:
> desktop <fff@sss.com> writes:
>
>
> you should use std::endl ... I assume you #include <iostream> and
> <ostream> , BTW
>


have now both included:

#include <iostream>
#include <ostream>

#ifdef bob
std::cout << "Bob is on\n" << std::endl;
#else
std::cout << "Bob is off\n" << std::endl;
#endif


but I still get the same error:

error: expected constructor, destructor, or type conversion before ‘<<’
token
make: *** [linux] Error 1
Maurizio Loreti

2007-10-02, 7:33 am

desktop <fff@sss.com> writes:

> but I still get the same error:
>
> error: expected constructor, destructor, or type conversion before
> ‘<<’ token
> make: *** [linux] Error 1


sorry, but I couldn't duplicate this behavior:

---------------------------------------------------------------------------

MLO@mlinux 9 $ cat foo.cxx
#include <iostream>
#include <ostream>

int main() {
#ifdef bob
std::cout << "Bob is on\n" << std::endl;
#else
std::cout << "Bob is off\n" << std::endl;
#endif
}
MLO@mlinux 10 $ g++ -std=c++98 -pedantic -W -Wall -O2 -o foo foo.cxx && ./foo
Bob is off

MLO@mlinux 11 $ g++ -std=c++98 -pedantic -W -Wall -Dbob -O2 -o foo foo.cxx && ./foo
Bob is on

MLO@mlinux 12 $

--
| Maurizio Loreti -- ROT13:ybergv@cq.vasa.vg | (@_
| Un. of Padova, Dept. of Physics, Padova, Italy | //\
| http://www.pd.infn.it/~loreti/mlo.html | V_/_
SM Ryan

2007-10-02, 7:33 am

desktop <fff@sss.com> wrote:
# I have this in a c++ file:
#
# #ifdef bob
# std::cout << "Bob is on\n" << endl;
# #else
# std::cout << "Bob is off\n" << endl;
# #endif
#
#
# But when compiling I get:
#
# error: expected constructor, destructor, or type conversion before ‘<<’

I'm seeing odd characters on either side of the <<.

Do you have stray non-ascii characters? You can use od, etc to
see the exact bytes in the file.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
Why are we here?
whrp
Scott Lurndal

2007-10-02, 7:28 pm

SM Ryan <wyrmwif@tango-sierra-oscar-foxtrot-tango.fake.org> writes:
>desktop <fff@sss.com> wrote:
># I have this in a c++ file:
>#
># #ifdef bob
># std::cout << "Bob is on\n" << endl;
># #else
># std::cout << "Bob is off\n" << endl;
># #endif
>#
>#
># But when compiling I get:
>#
># error: expected constructor, destructor, or type conversion before ‘<<’
>
>I'm seeing odd characters on either side of the <<.
>
>Do you have stray non-ascii characters? You can use od, etc to
>see the exact bytes in the file.
>


Looks like the special characters are smart quotes, inserted by the
usenet client software.

scott
Scott Lurndal

2007-10-02, 7:28 pm

desktop <fff@sss.com> writes:
>Maurizio Loreti wrote:
>
> have now both included:
>
>#include <iostream>
>#include <ostream>
>
>#ifdef bob
>std::cout << "Bob is on\n" << std::endl;
>#else
>std::cout << "Bob is off\n" << std::endl;
>#endif
>
>
>but I still get the same error:
>
>error: expected constructor, destructor, or type conversion before ‘<<’
>token
>make: *** [linux] Error 1


So run it through the pre-processor and look at the output. g++/c++ -E.

My guess is that you should look at the source line immediately preceeding
the #ifdef, particularly for a missing semi-colon.

scott
Paul Pluzhnikov

2007-10-03, 1:34 am

scott@slp53.sl.home (Scott Lurndal) writes:

>
> Looks like the special characters are smart quotes, inserted by the
> usenet client software.


They are inserted by newer versions of gcc, and they are "UTF
quotes". See e.g. http://scintilla.sourceforge.net/SciTEFAQ.html#GCCUTF8

Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com