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

strings in #if 0

having read the section on preprocessing (6.10) and not finding the
answer, is the following code acceptable? i have compilers which
accept it, accept it with a warning, and refuse to compile it. i'm
wondering which is correct.

#if 0
print FILEPTR "int main()

#endif

Jun 22 '06 #1
4 1326
"tedu" <tu@zeitbombe.org> writes:
having read the section on preprocessing (6.10) and not finding the
answer, is the following code acceptable? i have compilers which
accept it, accept it with a warning, and refuse to compile it. i'm
wondering which is correct.

#if 0
print FILEPTR "int main()

#endif


It is incorrect. Groups that are skipped must consist of valid
preprocessing tokens.
--
"C has its problems, but a language designed from scratch would have some too,
and we know C's problems."
--Bjarne Stroustrup
Jun 22 '06 #2

Ben Pfaff wrote:
"tedu" <tu@zeitbombe.org> writes:
having read the section on preprocessing (6.10) and not finding the
answer, is the following code acceptable? i have compilers which
accept it, accept it with a warning, and refuse to compile it. i'm
wondering which is correct.

#if 0
print FILEPTR "int main()

#endif


It is incorrect. Groups that are skipped must consist of valid
preprocessing tokens.


No, it is fine. The group consists of valid preprocessing tokens, one
of which is ". These preprocessing tokens must be ignored as the
standard dictates.

A compiler must accept it.

Jun 23 '06 #3
"Neil" <ne**@daikokuya.co.uk> writes:
Ben Pfaff wrote:
"tedu" <tu@zeitbombe.org> writes:
> having read the section on preprocessing (6.10) and not finding the
> answer, is the following code acceptable? i have compilers which
> accept it, accept it with a warning, and refuse to compile it. i'm
> wondering which is correct.
>
> #if 0
> print FILEPTR "int main()
>
> #endif


It is incorrect. Groups that are skipped must consist of valid
preprocessing tokens.


No, it is fine. The group consists of valid preprocessing tokens, one
of which is ". These preprocessing tokens must be ignored as the
standard dictates.

A compiler must accept it.


No, it's undefined behavior. (We've had a claim that it's illegal,
and one that it's legal; I figured we should cover all the
possibilities.)

C99 6.4p3:

A _token_ is the minimal lexical element of the language in
translation phases 7 and 8. The categories of tokens are:
keywords, identifiers, constants, string literals, and
punctuators. A preprocessing token is the minimal lexical element
of the language in translation phases 3 through 6. The categories
of preprocessing tokens are: header names, identifiers,
preprocessing numbers, character constants, string literals,
punctuators, and single non-white-space characters that do not
lexically match the other preprocessing token categories. If a '
or a " character matches the last category, the behavior is
undefined.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jun 23 '06 #4
"Neil" <ne**@daikokuya.co.uk> wrote:
Ben Pfaff wrote:
"tedu" <tu@zeitbombe.org> writes:
having read the section on preprocessing (6.10) and not finding the
answer, is the following code acceptable? i have compilers which
accept it, accept it with a warning, and refuse to compile it. i'm
wondering which is correct.

#if 0
print FILEPTR "int main()

#endif


It is incorrect. Groups that are skipped must consist of valid
preprocessing tokens.


No, it is fine. The group consists of valid preprocessing tokens, one
of which is ". These preprocessing tokens must be ignored as the
standard dictates.

A compiler must accept it.


Wrong, and wrong. From 6.4#3:

# The categories of preprocessing tokens are: ... string literals ... ,
# and single non-whitespace characters that do not lexically match the
# other preprocessing token categories. If a ' or " character matches
# the last category, the behavior is undefined.

Note the last sentence.

Richard
Jun 23 '06 #5

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

Similar topics

20
by: Ravi | last post by:
Hi, I have about 200GB of data that I need to go through and extract the common first part of a line. Something like this. >>>a = "abcdefghijklmnopqrstuvwxyz" >>>b = "abcdefghijklmnopBHLHT"...
17
by: Gordon Airport | last post by:
Has anyone suggested introducing a mutable string type (yes, of course) and distinguishing them from standard strings by the quote type - single or double? As far as I know ' and " are currently...
16
by: Paul Prescod | last post by:
I skimmed the tutorial and something alarmed me. "Strings are a powerful data type in Prothon. Unlike many languages, they can be of unlimited size (constrained only by memory size) and can hold...
4
by: agent349 | last post by:
First off, I know arrays can't be compared directly (ie: if (arrary1 == array2)). However, I've been trying to compare two arrays using pointers with no success. Basically, I want to take three...
25
by: Rainmaker | last post by:
Hi, Can anyone tell me an efficient algorithm to sort an array of strings? Keep in mind that this array is HUGE and so the algorithm should me efficient enough to deal with it. Thanks
6
by: Broeisi | last post by:
Hello, I wrote the tiny progam below just to understand arrays and strings better. I have 2 questions about arrays and strings in C. 1. Why is it that when you want to assign a string to an...
2
by: Potiuper | last post by:
Question: Is it possible to use a char pointer array ( char *<name> ) to read an array of strings from a file in C? Given: code is written in ANSI C; I know the exact nature of the strings to be...
19
by: pkirk25 | last post by:
I wonder if anyone has time to write a small example program based on this data or to critique my own effort? A file called Realm List.html contains the following data: Bladefist-Horde...
95
by: hstagni | last post by:
Where can I find a library to created text-based windows applications? Im looking for a library that can make windows and buttons inside console.. Many old apps were make like this, i guess ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...

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.