473,700 Members | 2,528 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 3353
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
1692
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
10640
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
40225
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
2129
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
3656
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
6639
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
2912
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
2785
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
7967
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
2914
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
8731
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9219
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8975
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
7819
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
6564
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
4660
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3097
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
2
2395
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2032
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.