473,908 Members | 4,934 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7309
"JKop" <NU**@NULL.NULL > wrote in message
news:yQ******** ***********@new s.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******** ***********@new s.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.c h> 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.c h> 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 AnalyzeDefineDi rective(std::st ring 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******** ***********@new s.indigo.ie...
Chris Theis posted:

"Chris Theis" <Ch************ *@nospam.cern.c h> 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 AnalyzeDefineDi rective(std::st ring 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*****@bluegr ass.net> schrieb im Newsbeitrag
news:41******** *******@bluegra ss.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
2860
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 to validate and transform some very large (potentially over 100MB) XML documents. This is related to another question I will post next, but for now, I want to focus on one particular topic. The data in question has particular business rules...
7
18931
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 stylehseet or is it a bug of mozilla? I am asking this because of IE and Opera work differently here. <style>
24
3365
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 use the header file of the class developed by me to access its functionality. so what should be there in the header file? Only the public methods declaration / data members of that class or the whole layout of the class along with its all private...
3
4147
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 (extern block and internal block), an identifier declared in the external block is known also in the internal block, while an identifier declared in the internal block is not known
9
1939
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, in ? A() File "x1x2.py", line 11, in A
5
1546
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 request form that ask a series of questions: TravelType: Domestic or International VisitType: (Customer, Internal Meeting, Seminar) TravelCost
32
3342
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 += i + j + k++;
3
1290
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: example: <rules> <rule01> <if> <or>
27
2805
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: ================ module.h ================ #ifndef __MODULE_HDR_INCLUDED__
0
10029
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, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9875
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,...
0
11335
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
11040
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,...
1
8094
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
7244
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
5930
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4765
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
3
3354
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.