473,407 Members | 2,306 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,407 software developers and data experts.

Preprecessor and white spaces

Hi!

I am trying to automate some work by using the preprocessor. Please
consider the following example:
-----------------------------------------------------------------
#define MY_CLASS(ClassType) \
class ##ClassType \
{ \
}

MY_CLASS(MyClassName);

int main()
{
return 0;
}

-----------------------------------------------------------------

The preprocessor output looks like this (I am using VC 8.0):

-----------------------------------------------------------------
classMyClassName { };

int main()
{
return 0;
}
-----------------------------------------------------------------

As you can see, the (intended) white space between the keyword class and
the argument is deleted, thus the generated code is not compileable.

Is there any way to get a white space between class and MyClassName? I
already searched on the web, but did not find anything.

Any help would be highly appreciated!

Kind regards,
Gernot
Apr 6 '07 #1
3 1180
Gernot Bauer schrieb:
>
-----------------------------------------------------------------
#define MY_CLASS(ClassType) \
class ##ClassType \
^^
This has to be deleted, of course. I don't know why I put it into my
macro :/ Now everything seems to work as expected.

Kind regards,
Gernot
Apr 6 '07 #2
In article <22***************************@news.inode.at>,
Gernot Bauer <gb****@sbox.tugraz.atwrote:
>Hi!

I am trying to automate some work by using the preprocessor. Please
consider the following example:
-----------------------------------------------------------------
#define MY_CLASS(ClassType) \
class ##ClassType \
{ \
}

MY_CLASS(MyClassName);

int main()
{
return 0;
}

-----------------------------------------------------------------

The preprocessor output looks like this (I am using VC 8.0):

-----------------------------------------------------------------
classMyClassName { };

int main()
{
return 0;
}
-----------------------------------------------------------------

As you can see, the (intended) white space between the keyword class and
the argument is deleted, thus the generated code is not compileable.

Is there any way to get a white space between class and MyClassName? I
already searched on the web, but did not find anything.

Any help would be highly appreciated!
You could get rid of ##. I'm sure you've only shown enough code to
zero in on the problem you're having, but I think most of us are
curious about what even that accomplishes especially considering the
default of class whatever {};?
--
Greg Comeau / 4.3.9 with C++0xisms now in beta!
Comeau C/C++ ONLINE == http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Apr 6 '07 #3
Hello!

Greg Comeau schrieb:
In article <22***************************@news.inode.at>,

You could get rid of ##. I'm sure you've only shown enough code to
As stated in my other post, I already figured that out. I make seldom
use of the preprocessor and somehow only thought about string
concatenation. Sometimes, you don't see the wood for the trees.
zero in on the problem you're having, but I think most of us are
curious about what even that accomplishes especially considering the
default of class whatever {};?
This is, as you guessed, only a minimal example to illustrate my problem.

The real problem I tried to address is the following: My custom
exception classes I use are rather basic and resemble std::exception.
When I create an exception hierarchy, I mainly have to do c&p. This is
annoying, and as it annoys me, I sometimes forget to make necessary
changes to the new class which results in a compiler error that annoys
me even more.
With the macros I wrote, I can automate this to some extent so I only
have to write something like

ABSTRACT_BASE_EXCEPTION(ExceptionBase);
DERIVED_EXCEPTION(ExceptionDerived, ExceptionBase, "My Default String");

in order to create those exception classes for me. I believe this also
helps me when I want to refactory my exception hierarchy (another
boring, but error-prone duty).

By now, I have written and tested the macros. I still have to test their
usefullness and how well they work together with automated documentation
tools like doxygen.

Kind regards,
Gernot
Apr 6 '07 #4

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

Similar topics

5
by: qwweeeit | last post by:
Hi all, I need to limit as much as possible the lenght of a source line, stripping white spaces (except indentation). For example: .. . max_move and AC_RowStack.acceptsCards ( self,...
4
by: ucfcpegirl06 | last post by:
Hi, I need help getting rid of trailing white spaces. I am searching a file for various data (not important) and retrieving it. I output the data if found to a file. An example would be:...
5
by: Jonathan Ng | last post by:
Hi, I was wondering if there was a way to include the white spaces in a string. Currently, I am using: scanf("%s", &input); However, this doesn't include the 'space' character or any other...
11
by: gopal srinivasan | last post by:
Hi, I have a text like this - "This is a message containing tabs and white spaces" Now this text contains tabs and white spaces. I want remove the tabs and white...
3
by: Prince | last post by:
I have some <RequiredFieldValidator> on my page and everything works fine except that there are lots of white spaces between the web server controls that are being validated. I've set the Display...
4
by: Andreas Prilop | last post by:
How many spaces should be displayed in A <span style="display:none">x</span> B between "A" and "B"? I notice that Mozilla displays one space and Internet Explorer (5 & 6) displays two spaces....
12
by: JA | last post by:
Is there a way to remove all the white space in the fields? I have been using Find-and-replace - looking for 2 or 3 or 4 or 10 spaces and replacing them with none. I don't want to replace single...
3
by: ayan4u | last post by:
well i need to deal with white spaces in charecter arrays... with static arrays its fine.. char ss; cin.getline(ss, sizeof ss); .... //deals with white spaces
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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:
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.