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

line directive

what is the purpose of the #line directive?
how is it suppose to be used?

I didn't see it mentioned in the faq and I can't make any sense of it from
the standard.

--
nethlek
Nov 13 '05 #1
2 9597
Mantorok Redgormor wrote:

what is the purpose of the #line directive?
how is it suppose to be used? From N869:


6.10.4 Line control

Constraints

[#1] The string literal of a #line directive, if present,
shall be a character string literal.

Semantics

[#2] The line number of the current source line is one
greater than the number of new-line characters read or
introduced in translation phase 1 (5.1.1.2) while processing
the source file to the current token.

[#3] A preprocessing directive of the form

# line digit-sequence new-line

causes the implementation to behave as if the following
sequence of source lines begins with a source line that has
a line number as specified by the digit sequence
(interpreted as a decimal integer). The digit sequence
shall not specify zero, nor a number greater than
2147483647.

[#4] A preprocessing directive of the form

# line digit-sequence "s-char-sequence-opt" new-line

sets the presumed line number similarly and changes the
presumed name of the source file to be the contents of the
character string literal.

[#5] A preprocessing directive of the form

# line pp-tokens new-line

(that does not match one of the two previous forms) is
permitted. The preprocessing tokens after line on the
directive are processed just as in normal text (each
identifier currently defined as a macro name is replaced by
its replacement list of preprocessing tokens). The
directive resulting after all replacements shall match one
of the two previous forms and is then processed as
appropriate.

In other words it can be used to play games with the compilers
opinion of the current file name and the current source line
number.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 13 '05 #2
Mantorok Redgormor wrote:
what is the purpose of the #line directive?
how is it suppose to be used?


This is usually used by code generators (e.g. lex/flex/bison/yacc), or
languages that compile to C instead of to assembly (e.g. f2c). If the
generated program contains a compile error, you can get an error/warning
in terms of the original file (which you wrote) instead of the
generated file (that the generator/translator wrote).

Example: a lex input file (sample.l) containing an error:

----- start of file
%%
fubar printf("a syntax error" 123);
%%
----- end of file

(pass it through lex)

$ lex sample.l
$ wc -l lex.yy.c

1499 lex.yy.c

(the generated file is no less than 1499 lines long)

$ cc lex.yy.c

sample.l: In function `yylex':
sample.l:2: error: parse error before numeric constant

(Thanks to #line, I get an error in terms of the original, while the
faulty printf statement actually ends up line 605 of lex.yy.c)
Best regards,

Sidney

Nov 13 '05 #3

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

Similar topics

2
by: Robert | last post by:
I am using the php4-cgi Debian package which is based on PHP 4.3.4. I have problems when running php4 on the command line. If I say something like $ php4 index.cgi a number of variables...
3
by: Charles L | last post by:
Can someone provide me of an example of the use of the #line preprocessor directive? I am not 100% sure how you use it. Charles L
1
by: vishal | last post by:
What does #line 182 parser.y mean in a C program?
4
by: Cal Lidderdale | last post by:
My input line is i1,i2,i3,i4,i5,i6,i7,i8^,...i596,597, ... 14101,14102...NL/CR very long line of data - I only want the first 8 items and the delimiter between 8 & 9 is a carrot "^". The line...
14
by: Vlad | last post by:
Please consider this code public class MyClass{ public bool MyMethod1(){ return false; } public bool MyMethod2(){ int x=0,y=1/x; return false; }
0
by: AA | last post by:
Hi, I have a C++ project in DOT NET. I am using the __FILE__ and __LINE__ to print the current file and line number. I do not want the file anem with the full path to be printed. So I used the...
11
by: xdevel | last post by:
Hi, I don't understand option. if I write: #line 100 "file" I change file numeration to start to line 100 but what "file" ? any example?
2
by: Swoozie Pellegrino | last post by:
Hi, all. I'm having a helluva time with VS.NET 2005 and ASP.NET 2.0. When I add one line to my ASPX page, it causes the IDE to bomb with the dialog that says: "Microsoft Visual Studio 2005...
7
by: J.H.Kim | last post by:
Hi, everyone I saw the preprocessor "#line " in some source codes. It was like this : #line 2972 "ifupdown.nw" Please tell me what is the meaning of that "#line"? Thanks in advance.
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: 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:
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
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: 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
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.