473,385 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

preprocessor problem

$ cat test.c

#include<stdio.h>
#define PRINT(s) printf(#s);
int main(void){
PRINT(use \ ("backslash") not /);
return 0;
}

$ gcc -E test.c |tail
# 679 "/usr/include/stdio.h" 3

# 2 "test.c" 2

int main(void){
printf("use \ (\"backslash\") not /");
return 0;
}

$gcc -g -o test test.c
test.c:4:40: warning: unknown escape sequence: '\040'

Why is \ not put in before \ ?
observe that \ is put before " i.e., in (\"backslash\")

Jun 6 '06 #1
3 3339
onkar wrote:
$ cat test.c

#include<stdio.h>
#define PRINT(s) printf(#s);
int main(void){
PRINT(use \ ("backslash") not /);
return 0;
}

$ gcc -E test.c |tail
# 679 "/usr/include/stdio.h" 3

# 2 "test.c" 2

int main(void){
printf("use \ (\"backslash\") not /");
return 0;
}

$gcc -g -o test test.c
test.c:4:40: warning: unknown escape sequence: '\040'

Why is \ not put in before \ ?
observe that \ is put before " i.e., in (\"backslash\")


\ will get doubled if and only if it is part of a string or character
constant (there's one possible exception, but you'll probably not have
to care about that yet). If \ always got doubled, you wouldn't be able
to use any escape sequences. So:

PRINT(\n) will expand to printf("\n");

However,

PRINT("\n") will expand to printf("\"\\n\"");
PRINT('\n') will expand to printf("'\\n'");

Jun 6 '06 #2
Why isn't my program compiling

Harald van Dijk wrote:
onkar wrote:
$ cat test.c

#include<stdio.h>
#define PRINT(s) printf(#s);
int main(void){
PRINT(use \ ("backslash") not /);
return 0;
}

$ gcc -E test.c |tail
# 679 "/usr/include/stdio.h" 3

# 2 "test.c" 2

int main(void){
printf("use \ (\"backslash\") not /");
return 0;
}

$gcc -g -o test test.c
test.c:4:40: warning: unknown escape sequence: '\040'

Why is \ not put in before \ ?
observe that \ is put before " i.e., in (\"backslash\")


\ will get doubled if and only if it is part of a string or character
constant (there's one possible exception, but you'll probably not have
to care about that yet). If \ always got doubled, you wouldn't be able
to use any escape sequences. So:

PRINT(\n) will expand to printf("\n");

However,

PRINT("\n") will expand to printf("\"\\n\"");
PRINT('\n') will expand to printf("'\\n'");


Jun 6 '06 #3

onkar wrote:
Harald van Dijk wrote:
onkar wrote:
$ cat test.c

#include<stdio.h>
#define PRINT(s) printf(#s);
int main(void){
PRINT(use \ ("backslash") not /);
return 0;
}

$ gcc -E test.c |tail
# 679 "/usr/include/stdio.h" 3

# 2 "test.c" 2

int main(void){
printf("use \ (\"backslash\") not /");
return 0;
}

$gcc -g -o test test.c
test.c:4:40: warning: unknown escape sequence: '\040' [ snip explanation ] Why isn't my program compiling


It does compile; are you by any chance doing
../a.out
instead of
../test
(note the command line you've used).
However, the compiler is not too happy with your code.
The compiler doesn't know what '\<space>' means: and
gives out that `warning: ...'\040' `. Look up the ASCII chart
for space.

Jun 6 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jakob Simon-Gaarde | last post by:
Some project includes files from different libraries lib1,lib2 and lib3 all having each there own version header file. I need to be able to pick up these values in a single define value...
205
by: Jeremy Siek | last post by:
CALL FOR PAPERS/PARTICIPATION C++, Boost, and the Future of C++ Libraries Workshop at OOPSLA October 24-28, 2004 Vancouver, British Columbia, Canada http://tinyurl.com/4n5pf Submissions
24
by: Nudge | last post by:
I have an array, and an unrolled loop which looks like this: do_something(A); do_something(A); .... do_something(A); I thought: why should I type so much? I should write a macro. So I was...
13
by: Chris Croughton | last post by:
Is the following code standard-compliant, and if so what should it do? And where in the standard defines the behaviour? #include <stdio.h> #define DEF defined XXX int main(void) { int...
9
by: Walter Roberson | last post by:
I have run into a peculiarity with SGI's C compiler (7.3.1.2m). I have been reading carefully over the ANSI X3.159-1989 specification, but I cannot seem to find a justification for the behaviour....
2
by: Paolo | last post by:
I imported a VC++6.0 project into VC++7.1. The conversion operation makes a mess with Preprocessor Definitions, adding a "$(NoInherit)" for each file. For example: I had a DLL project in VC++6.0...
8
by: claus.tondering | last post by:
I need to write a macro that inserts someStruct m_someStruct; into another struct declaration. The problem is that if the programmer specifies one particluar struct (called alpha), nothing...
32
by: spibou | last post by:
Is the output of the C preprocessor deterministic ? What I mean by that is , given 2 compilers which conform to the same standard, will their preprocessors produce identical output given as input...
25
by: Gernot Frisch | last post by:
Hi, I want to build a encryption macro set, that can crypt: char secret = CRYPT("KungFu"); to anything unreadable, and then have a function: char* DECRYPT(char* str) { ...
31
by: Sam of California | last post by:
Is it accurate to say that "the preprocessor is just a pass in the parsing of the source file"? I responded to that comment by saying that the preprocessor is not just a pass. It processes...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.