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

getting cpp to insert a newline

Hi all,

I'm trying to get a newline into preprocessed output and I'm not sure
how to do it, if it's at all possible.

For example:

#define _TEST i want this on one line / and this on the next
_TEST

---shoud give me:

i want this one one line
and this on the next

Is there a trigraph or some kind of escape sequence for this? I don't
see one but I may be wrong.

Thanks,
Jason

Nov 14 '05 #1
8 3824
In article <11*********************@o13g2000cwo.googlegroups. com>,
jiversen <ji******@d2.com> wrote:
:I'm trying to get a newline into preprocessed output and I'm not sure
:how to do it, if it's at all possible.

:For example:

:#define _TEST i want this on one line / and this on the next
:_TEST

:---shoud give me:

:i want this one one line
:and this on the next

Sorry, you can't portably do it. By the time preprocessing is finished,
you are at the end of translation phase 4; phase 5 converts
escape literals into the execution character set [e.g., \b gets
converted into backspace character itself]; phase 6
concatenates adjacent string literals, and that takes you to phase 7.
At phase 7, whitespace is not significant. If you back-reason
from phase 7, you see that the result of preprocessing only has to
preserve enough information about whitespacing so that it doesn't
accidently create escape sequences that weren't already present.

To put it another way: the result of pre-processing only be
something with equivilent semantic meaning, and there is no case
in which splitting a line is semantically meaningful in C,
except for preprocessor facilities. However, the preprocessor
doesn't allow you to build up preprocessor facilities -- you cannot,
for example, use a #define to create something that, after parameter
replacement in the program, will result in a -new- #define being processed.

As I was firmly informed just last week, if you are trying to do
something in which the actual -form- of the output of preprocessing
matters, then you are trying to do something not supported by the
C preprocessor in any portable way.
--
Strange but true: there are entire WWW pages devoted to listing
programs designed to obfuscate HTML.
Nov 14 '05 #2
Thank you very much for your reply. Its makes perfect sense.

Its true, I'm attempting to use "cpp" for something thats not C - where
whitespace and newlines ARE significant.

Thanks again,
Jason

Nov 14 '05 #3
jiversen wrote:
Hi all,

I'm trying to get a newline into preprocessed output and I'm
not sure how to do it, if it's at all possible.
The C language describes translation phases, not implementation
options like cpp. Typically, preprocessing is mostly translation
phases 1 through 4, but there's quite a gray area.
For example:

#define _TEST i want this on one line / and this on the next
_TEST

---shoud give me:

i want this one one line
and this on the next
Why are you bothering with cpp output?

What is the bigger problem that you're trying to solve?
Is there a trigraph or some kind of escape sequence for this?


No. Standard preprocessing directives are always on one logical
source line. The \ splice mechanism just joins physical source
lines.

--
Peter

Nov 14 '05 #4
I'm doing miscellaneous scripting and I find the cpp macros quite
useful for a number of things. I'm trying to very easily lever the
usefulness of the #includes and #define(x) directives for a data file
that I parse later.

Is there another option for doing preprocessing that would maybe have
an extended syntax?

Nov 14 '05 #5
In article <11**********************@f14g2000cwb.googlegroups .com>,
jiversen <ji******@d2.com> wrote:
:Is there another option for doing preprocessing that would maybe have
:an extended syntax?

m4 is the usual answer.
--
Ceci, ce n'est pas une idée.
Nov 14 '05 #6
On 9 Feb 2005 16:27:32 -0800, "jiversen" <ji******@d2.com> wrote:
Thank you very much for your reply. Its makes perfect sense.

Its true, I'm attempting to use "cpp" for something thats not C - where
whitespace and newlines ARE significant.

There are general purpose macro processors available. One that I've
used is called M4. Do a Google search for macro processor, and you'll
get links to some.

--
Al Balmer
Balmer Consulting
re************************@att.net
Nov 14 '05 #7
I'm trying out m4 right now. Odd syntax with the backtick thing but I
think it'll do my bidding.

Thanks all.

Nov 14 '05 #8
On 9 Feb 2005 16:27:32 -0800, jiversen
<ji******@d2.com> wrote:
Thank you very much for your reply. Its makes perfect sense.

Its true, I'm attempting to use "cpp" for something thats not C - where
whitespace and newlines ARE significant.


If you want something you can hack to get a similar effect, you could
look at my xcpp (http://www.keristor.co.uk/stuff/xcpp-0.5.5.tar.gz). It
doesn't implement #include files (that's not its intent) but it may be a
start. Or it may not, depending how unclear you find my code <g>...

Chris C
Nov 14 '05 #9

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

Similar topics

20
by: akej via SQLMonster.com | last post by:
Hi, i have table with 15 columns CREATE TABLE . ( PRIMARY KEY , NULL , NULL , NULL , NULL , (50) NULL , NULL
14
by: Geoff Cox | last post by:
Hello, I am trying to get each "Situation - etc" in document.getElementById("Slider1ValueText").innerHTML += escape("\n") + "Situation - " + title + ": "; to start on a new line in the...
8
by: Amira | last post by:
Hi all, I am reading from a text file and then write into an array line by line. For that reason a writeline function has been created. When the float numbers are written into the array I would...
8
by: 73blazer | last post by:
Hello, I'm looking for a way to make some of my insert templates more readable by placing comments in between the values. I cannot seem to find a way to do this with DB2, is there a way? I'm...
7
by: deko | last post by:
In VB, I would do this for a new line: str = "text here" & VbCrLf & "more text" For other characters, I would use the ascii code: For example, Chr(34) is a double quote ("). how do I do...
1
by: Mr. Roundhill | last post by:
Hi there, I am trying to put a newline into a headertext property of a detailsview in my asp.net application. I've tried \r\n with no luck, and putting <br /> in the asp doesn't work either. ...
8
by: cypher543 | last post by:
This has been driving me insane for the last hour or so. I have search everywhere, and nothing works. I am trying to use the subprocess module to run a program and get its output line by line. But,...
9
by: Peter Hartlén | last post by:
I understand that the\n and \r only means something to the C# compiler so when retrieving a line like "Hello\r\nWorld" from a resource file (localized form or self made resource file), it prints...
6
by: sdanda | last post by:
I am using a tooltip control for a picturebox control. I would like to display the caption of the tooltip in newline. How to do this? My picturebox name is help and tooltip name is ttp and I am...
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: 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: 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?
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.