473,602 Members | 2,811 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3348
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
1686
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 DEP_PROJECT. pseudo preprocessor code would look like this: 1. Lib1 version header is included: #define PROJ_NAME "Lib1" #define PROJ_VERSION 102
205
10539
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
40140
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 looking to write something along the lines of:
13
2111
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 defined = 2;
9
3649
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. Could someone point me to the appropriate section, or else confirm the behaviour as a bug? For a particular project, I am using the C preprocessor phase only. I am not using the standalone program 'cpp' because proper functioning of my project...
2
6633
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 where the definitions were: _UNICODE,_DEBUG,_WIN32_DCOM,WIN32,_WINDOWS,_WINDLL,_AFXDLL,_USRDLL In VC++7.1, these are the preprocessor definitions of the project (right-click the project in Solution Explorer and choose Properties -> C++ ->...
8
2906
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 should be inserted. So, is it possible to write a macro that does this: MACRO(alpha) expands to nothing
32
2762
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 the same file ? If not then how much variation is allowed ? Is it just a bit more or less white space here and there or could could there be larger differences ? If the output is not deterministic then is it possible that the output of the...
25
7961
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
2900
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 statements that the compiler does not process. The good people in the alt.comp.lang.learn.c-c++ newsgroup insist that the preprocessor is just one of many passes. The preprocessor processes a grammer unique to the preprocessor and only that grammer. ...
0
7920
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8054
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6730
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5867
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5440
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3944
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2418
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1510
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1254
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.