473,383 Members | 1,789 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,383 software developers and data experts.

Rules for #define


#define LRESULT long
Here's what I have so far:
1) The # must be the first non-white-space character on the line.
2) There may be any number of white-space characters between # and "define".
3) Any number of white space characters may reside between LRESULT and long,
but the minimum amount is 1.
4) White-space characters before and after "long" are not substituted in the
file.
5) If it's multiline, as in:

# define LRESULT \
long

then the backward slash must *immediately* preceed the '\n'.

That's all I've got so far. So what I'm looking to find out is:
A) Many any amount of white-space characters seperate "define" and
"LRESULT"?
B) Is the following legal?:

#\
def\
ine \
LRESULT \
long

C) What signals the end of the directive, is it '\n'? If you have a
directive at the very end of the file, and there's no '\n' at the end, then
is the directive valid?
D) What's a white-space character? Can anyone list them. Here's the ones I
know:

' ' (space)
' ' (horizontal tab... does it have a "universal" code, as does
'\n'?)

-JKop
Jul 22 '05 #1
9 7279
"JKop" <NU**@NULL.NULL> wrote in message
news:yQ*******************@news.indigo.ie...

#define LRESULT long
Here's what I have so far:
1) The # must be the first non-white-space character on the line.
2) There may be any number of white-space characters between # and
"define".
3) Any number of white space characters may reside between LRESULT and
long,
but the minimum amount is 1.
4) White-space characters before and after "long" are not substituted in
the
file.
5) If it's multiline, as in:

# define LRESULT \
long

then the backward slash must *immediately* preceed the '\n'.

That's all I've got so far. So what I'm looking to find out is:
One key thing: comments may be included! and they count as whitespace:
/* */ or // \n
A) Many any amount of white-space characters seperate "define" and
"LRESULT"? yes
B) Is the following legal?:

#\
def\
ine \ no: \\ + \n counts as whitespace LRESULT \
long

C) What signals the end of the directive, is it '\n'? If you have a
directive at the very end of the file, and there's no '\n' at the end,
then
is the directive valid? An ISO C++ conformant source file is *required* to end with a \n.
D) What's a white-space character? Can anyone list them. Here's the ones I
know: This is platform-dependent, and specified by 'isspace()' in <cctype>
' ' (space)
' ' (horizontal tab... does it have a "universal" code, as does Yes: \t '\n'?)

I typically also include: \r
This said, if you are working on parsing a C++ file, I would
recommend using a dedicated tool, such as GNU flex, boost::spirit.
It will save you a lot of time and effort...
Cheers,
Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Jul 22 '05 #2
> B) Is the following legal?:

Why does it matter. I thought you were only concerned with the laws of
physics?

AASP ( Avoid Admitted Software Pirates )

Jeff F
Jul 22 '05 #3
Jeff Flinn posted:
B) Is the following legal?:


Why does it matter. I thought you were only concerned with the laws of
physics?

AASP ( Avoid Admitted Software Pirates )

Jeff F


Looks like some-one's never encountered homonyms.
-JKop
Jul 22 '05 #4

"JKop" <NU**@NULL.NULL> schrieb im Newsbeitrag
news:yQ*******************@news.indigo.ie...

#define LRESULT long
Here's what I have so far:
1) The # must be the first non-white-space character on the line.
2) There may be any number of white-space characters between # and "define".

3) Any number of white space characters may reside between LRESULT and long, but the minimum amount is 1.
4) White-space characters before and after "long" are not substituted in the file.
5) If it's multiline, as in:

# define LRESULT \
long

then the backward slash must *immediately* preceed the '\n'.

That's all I've got so far. So what I'm looking to find out is:
A) Many any amount of white-space characters seperate "define" and
"LRESULT"?
Yes.


B) Is the following legal?:

#\
def\
ine \
LRESULT \
long
Yes it is. Each new-line character with an immediately preceeding backslash
is deleted in the second translation phase.
C) What signals the end of the directive, is it '\n'? If you have a
directive at the very end of the file, and there's no '\n' at the end, then is the directive valid?

For any non-empty source file that does not end in a new-line character the
behavior is undefined. This is also valid for non-empty files that end in a
new-line character with a preceeding backslash.

D) What's a white-space character? Can anyone list them. Here's the ones I
know:

' ' (space)
' ' (horizontal tab... does it have a "universal" code, as does
'\n'?)


The standard specifies space, horizontal-tab, new-line, vertical-tab, and
form-feed as white-space characters.

HTH
Chris
Jul 22 '05 #5

"Chris Theis" <Ch*************@nospam.cern.ch> schrieb im Newsbeitrag
news:ck**********@sunnews.cern.ch...

[SNIP]

If you're really going for it you should also pay attention to tri-graph
sequences.

Cheers
Chris
Jul 22 '05 #6
Chris Theis posted:

"Chris Theis" <Ch*************@nospam.cern.ch> schrieb im Newsbeitrag
news:ck**********@sunnews.cern.ch...

[SNIP]

If you're really going for it you should also pay attention to tri-graph
sequences.

Cheers
Chris


Well so far I've got approx. 539 lines of code written...
Anyway, once I've "processed" a #define statement, I'm going to have it all
nicely cleaned up, all white-space characters removed, and it'll be passed
to:

void AnalyzeDefineDirective(std::string const &first, std::string const
&second);
From there, that particular function won't have to worry about white spaces
(including comments). It'll compute "is parameter 2 an intrinsic type?", "is
parameter 2 a literal", "is parameter 1 a macro function"... and so on.
-JKop
Jul 22 '05 #7


JKop wrote:
#define LRESULT long

Here's what I have so far:

1) The # must be the first non-white-space character on the line.
2) There may be any number of white-space characters between # and "define".

3) Any number of white space characters may reside between LRESULT and long,
but the minimum amount is 1.

4) White-space characters before and after "long" are not substituted in the
file.

5) If it's multiline, as in:

# define LRESULT \
long

then the backward slash must *immediately* preceed the '\n'.

That's all I've got so far. So what I'm looking to find out is:

A) Many any amount of white-space characters seperate "define" and
"LRESULT"?

yes that should be fine.

B) Is the following legal?:

#\
def\
ine \
LRESULT \
long

I think that *may* not be legal, because the newlines are treated as
whitespace. Borland won't compile it at any rate...

C) What signals the end of the directive, is it '\n'? If you have a
directive at the very end of the file, and there's no '\n' at the end, then
is the directive valid?

yes newline terminates the directive. technically, the directive isn't valid at
the end of the file if there is no newline.. The standards say that input files
MUST be terminated by a newline; deviating from this causes undefined behavior.
Practically speaking, some compilers will let you get by with it. And some
won't. I used to have all sorts of troubles because I had an editor that
constantly stripped the newline from the end of the file... windows compilers
were forgiving but an embedded compiler I used just discarded the last line in
that case, if that line was a directive.

D) What's a white-space character? Can anyone list them. Here's the ones I
know:

' ' (space)
' ' (horizontal tab... does it have a "universal" code, as does
'\n'?)


I'm not sure what the standards say. the C language iswhitespace() seems to
consider the following things as space characters '\t' (universal code for tab)
'\n' \x0b' (???) '\x0c' (form feed) '\r' (universal code for CR). I have a
group of files I use that have embedded form feeds (I think the author set it up
to pretty-print the files one function per page) and I know the compilers I've
run them through do treat them as white space.

David

Jul 22 '05 #8

"JKop" <NU**@NULL.NULL> schrieb im Newsbeitrag
news:Ga*******************@news.indigo.ie...
Chris Theis posted:

"Chris Theis" <Ch*************@nospam.cern.ch> schrieb im Newsbeitrag
news:ck**********@sunnews.cern.ch...
[SNIP]

If you're really going for it you should also pay attention to tri-graph
sequences.

Cheers
Chris


Well so far I've got approx. 539 lines of code written...
Anyway, once I've "processed" a #define statement, I'm going to have it

all nicely cleaned up, all white-space characters removed, and it'll be passed
to:

void AnalyzeDefineDirective(std::string const &first, std::string const
&second);
From there, that particular function won't have to worry about white spaces (including comments). It'll compute "is parameter 2 an intrinsic type?", "is parameter 2 a literal", "is parameter 1 a macro function"... and so on.


It would be interesting to see that code if you have a running version.

Chris
Jul 22 '05 #9

"David Lindauer" <ca*****@bluegrass.net> schrieb im Newsbeitrag
news:41***************@bluegrass.net...
[SNIP]

B) Is the following legal?:

#\
def\
ine \
LRESULT \
long

I think that *may* not be legal, because the newlines are treated as
whitespace. Borland won't compile it at any rate...


Actually the example given above is compliant with the standard, which says
that new-lines with preceeding backslashes are treated in a special way. The
whole statement is concatenated before the preprocessor & the syntax
checking kicks in.

[SNIP]

D) What's a white-space character? Can anyone list them. Here's the ones I know:

' ' (space)
' ' (horizontal tab... does it have a "universal" code, as does
'\n'?)
I'm not sure what the standards say. the C language iswhitespace() seems

to consider the following things as space characters '\t' (universal code for tab) '\n' \x0b' (???) '\x0c' (form feed) '\r' (universal code for CR). I have a group of files I use that have embedded form feeds (I think the author set it up to pretty-print the files one function per page) and I know the compilers I've run them through do treat them as white space.


The standard specifies space, horizontal-tab, new-line, vertical-tab, and
form-feed as white-space characters.

Cheers
Chris
Jul 22 '05 #10

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

Similar topics

1
by: Mike | last post by:
Note: My XML experience to date has (unfortunately) been limited to reading and thinking, rather than implementation. Anyway, I am in the process of trying to figure out the most efficient way...
7
by: Marek Mänd | last post by:
When using <TABLE rules="all"> Mozilla 1.6 and previous versions draw a nasty interiour border, which doesnt go away though I have on TD's css border:none set. Is it something wrong with my...
24
by: ypjofficial | last post by:
Hello all, I have written a class with many private data members.and i am putting it in a separate dll file. Now when i link that file while writing my main program module,natuarally i have to...
3
by: fctk | last post by:
are the following rules correct in C89/C90? ---- SCOPE RULES 1) the scope of an identifier declared inside a block is the block in which it is declared; 2) when you have nested blocks...
9
by: NevilleDNZ | last post by:
Can anyone explain why "begin B: 123" prints, but 456 doesn't? $ /usr/bin/python2.3 x1x2.py begin A: Pre B: 123 456 begin B: 123 Traceback (most recent call last): File "x1x2.py", line 13,...
5
by: sck10 | last post by:
Hello, I need to create a Business Rules table that can be pulled into the web page and use it as criteria for who should receive the approval email. For example, I have created a travel...
32
by: silpau | last post by:
hi, i am a bit confused on expression evaluation order in expressions involving unary increment.decrement operators along with binary operators. For example in the following expression x...
3
by: jonny | last post by:
I have a python code that manages some parameters using some variable rules that may change from day to day. I'd like that the code will self-modify according to rules parsed from a xml file: ...
27
by: matt | last post by:
Hello group, I'm trying to become familiar with the information hiding design rules, and I have a lot (3) of questions for all you experts. AFAIK, a generic module has 2 files: ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.