www.digitalmars.com         C & C++   DMDScript  

c++ - Is it possible to "preprocess only"?

reply Paul Smirnov <s.paul mail.ru> writes:
Hello all,

As far as I understand, standard C preprocessor works with text files and
knows nothing about C but that's not right with DMC which refuses to
preprocess ("-e" option) plain text files.

I mean, is it right that there's no way to use DMC to preprocess non-c (or
invalid c) files? Am I missing something? I get lexical errors with DMC where
I get correctly preprocessed text files with "cl /P" or "gcc -E".

Thanks,
Paul.
Nov 13 2006
parent reply Walter Bright <newshound digitalmars.com> writes:
Paul Smirnov wrote:
 As far as I understand, standard C preprocessor works with text files and
 knows nothing about C but that's not right with DMC which refuses to
 preprocess ("-e" option) plain text files.
 
 I mean, is it right that there's no way to use DMC to preprocess non-c (or
 invalid c) files? Am I missing something? I get lexical errors with DMC where
 I get correctly preprocessed text files with "cl /P" or "gcc -E".

A standard compliant preprocessor will not work with text files that are invalid C code. The preprocessor is defined to work by tokenizing the source text into preprocessor tokens; if there are non-C tokens in the source text, it will (correctly) fail.
Nov 13 2006
next sibling parent reply Me & My <kirankhan005 hotmail.com> writes:
any one wants help in programming ( c++ ), then i m present at
here e-mail me at: kirankhan005 hotmail.com, for any Question in
C++
Nov 20 2006
next sibling parent reply ralph <ralph.hipps gmail.com> writes:
ok, dusting off many years of rust in my C programming, trying dmc, and what
seems
to be perfectly valid cpp code (hello world) generates three errors, mostly abut
expecting ; or whatever after } or { or return statement.

I assume this is a setup issue, any thoughts?
Nov 23 2006
parent reply Walter Bright <newshound digitalmars.com> writes:
ralph wrote:
 ok, dusting off many years of rust in my C programming, trying dmc, and what
seems
 to be perfectly valid cpp code (hello world) generates three errors, mostly
abut
 expecting ; or whatever after } or { or return statement.
 
 I assume this is a setup issue, any thoughts?

Try the -cpp switch.
Nov 23 2006
parent reply ralph <ralph.hipps gmail.com> writes:
code:

#include <iostream.h>


int main();
{
cout <<"Hello World!\n";
    return 0;
}

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

error:

{
^
hello.cpp(5) : Error: '=', ';' or ',' expected
    return 0;
         ^
hello.cpp(7) : Error: '=', ';' or ',' expected
}
^
hello.cpp(8) : Error: identifier or '( declarator )' expected
--- errorlevel 1
Nov 23 2006
next sibling parent ralph <ralph.hipps gmail.com> writes:
and that's the same error with the -cpp switch.
Nov 23 2006
prev sibling parent reply Walter Bright <newshound digitalmars.com> writes:
ralph wrote:
 #include <iostream.h>
 
 
 int main();
 {
 cout <<"Hello World!\n";
     return 0;
 }
 

Remove the ; after main().
Nov 23 2006
parent ralph <ralph.hipps gmail.com> writes:
that was it!!! I copied the wrong example.
Nov 23 2006
prev sibling parent reply ralph <ralph.hipps gmail.com> writes:
this should work, right?

code:

#include <iostream.h>
int main()
{
int x = 5;
int y = 7;
cout "\n";
cout << x + y << " " << x * y;
cout "\n";
return 0;
}

error:

cout "\n";
        ^
ch1_1.cpp(6) : Error: ';' expected following declaration of struct member
cout "\n";
        ^
ch1_1.cpp(8) : Error: ';' expected following declaration of struct member
--- errorlevel 1
Nov 23 2006
parent reply Walter Bright <newshound digitalmars.com> writes:
ralph wrote:
 this should work, right?
 
 code:
 
 #include <iostream.h>
 int main()
 {
 int x = 5;
 int y = 7;
 cout "\n";

need an operator between cout and "\n"
 cout << x + y << " " << x * y;
 cout "\n";
 return 0;
 }
 
 error:
 
 cout "\n";
         ^
 ch1_1.cpp(6) : Error: ';' expected following declaration of struct member
 cout "\n";
         ^
 ch1_1.cpp(8) : Error: ';' expected following declaration of struct member
 --- errorlevel 1
 

Nov 23 2006
parent reply ralph <ralph.hipps gmail.com> writes:
yep, that was it!!

I have this html 'book' called teach yourself c++ in 21 days, and I copy and
paste
the examples into the editor and compile them, and they seem to have syntax
errors
sometimes. Maybe the rest will be better, and maybe this is a good way to
learn, I
dunno, but it seems odd that the author would do this.

It's also odd that I'm not getting better error messaging from any of the
compilers, that would make it easier to fix the errors. I am trying out dmc,
turbo
c++ 3.0, and turbo c++ 10.1. All give basically the same cryptic error message.
Anything better out there? Ideally I'd like to find something to make games
with,
something that I can do graphics and sound with, not create applications or
standard forms or the like. More of a console app I guess?
Nov 24 2006
parent Walter Bright <newshound digitalmars.com> writes:
ralph wrote:
 It's also odd that I'm not getting better error messaging from any of the
 compilers, that would make it easier to fix the errors. I am trying out dmc,
turbo
 c++ 3.0, and turbo c++ 10.1. All give basically the same cryptic error message.
 Anything better out there? Ideally I'd like to find something to make games
with,
 something that I can do graphics and sound with, not create applications or
 standard forms or the like. More of a console app I guess?

Lousy error messages is a standard feature of C++. It's fallout from the syntax being so complicated, the compiler cannot very well guess what you were trying to do.
Nov 24 2006
prev sibling parent reply Paul Smirnov <s.paul mail.ru> writes:
 A standard compliant preprocessor will not work with text files that are
 invalid C code. The preprocessor is defined to work by tokenizing the
 source text into preprocessor tokens; if there are non-C tokens in the
 source text, it will (correctly) fail.

Right, preprocessor works with C tokens but not necessary with C programs. Here's an example: -[cut a.c]----------------- #define world Earth hello, world -[end cut]----------------- Everything is built from correct tokens but "dmc -e a.c" refuses to preprocess the "program" with the following error: a.c(2) : Error: missing ',' between declaration of 'The' and 'Earth' Am I still wrong?
Dec 01 2006
next sibling parent Paul Smirnov <s.paul mail.ru> writes:
== Quote from Paul Smirnov (s.paul mail.ru)'s article
 A standard compliant preprocessor will not work with text files that are
 invalid C code. The preprocessor is defined to work by tokenizing the
 source text into preprocessor tokens; if there are non-C tokens in the
 source text, it will (correctly) fail.

an example:

Oops... It was: -[cut a.c]----------------- #define world The Earth hello, world -[end cut]-----------------
 Everything is built from correct tokens but "dmc -e a.c" refuses to preprocess
the
 "program" with the following error:
 a.c(2) : Error: missing ',' between declaration of 'The' and 'Earth'
 Am I still wrong?

Dec 01 2006
prev sibling parent Walter Bright <newshound digitalmars.com> writes:
Paul Smirnov wrote:
 A standard compliant preprocessor will not work with text files that are
 invalid C code. The preprocessor is defined to work by tokenizing the
 source text into preprocessor tokens; if there are non-C tokens in the
 source text, it will (correctly) fail.

Right, preprocessor works with C tokens but not necessary with C programs. Here's an example: -[cut a.c]----------------- #define world Earth hello, world -[end cut]----------------- Everything is built from correct tokens but "dmc -e a.c" refuses to preprocess the "program" with the following error: a.c(2) : Error: missing ',' between declaration of 'The' and 'Earth' Am I still wrong?

dmc is still running the c compiler. All -e does is to send preprocessed output to the console when an error is diagnosed. To preprocess only, use the standalone preprocessor, sppn.exe.
Dec 01 2006