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

# inside a macro body

Hello All,

We're using in-house C pre processor for Assembly development.
We'd like to move to a standard "C" pre processor (such as gcc's "cpp").

However we have the following problem:
Out assembly code have the following syntax:
move #2, d1;

How can I write a macro that will produce the above line?
If I try:
#define mv(reg) move #2, reg;
I get (for cpp -E):
f:1:23: '#' is not followed by a macro parameter

I've tried with ## and \# but it doesn't work.
Is there a way around this?

Thanks.
Miki
Nov 14 '05 #1
6 7701
Miki Tebeka <mi*********@zoran.com> wrote:
Hello All, Out assembly code have the following syntax:
move #2, d1; How can I write a macro that will produce the above line?
If I try:
#define mv(reg) move #2, reg;
In definitions of function-like macros # and ## are operators.
I get (for cpp -E):
f:1:23: '#' is not followed by a macro parameter I've tried with ## and \# but it doesn't work.
Is there a way around this?


Try this:

#define HASH2 #2
#define mv(reg) move HASH2, reg;

[Note:
If you're thinking of producing "#2" by pasting "#" and "2", then
this will never work, because "#2" is not a valid token:
#define HASH #
#define xcat(a, b) a ## b
#define cat(a, b) xcat(a, b)
#define mv_dest(n, reg) move cat(HASH, n), reg;
mv_dest(2, d1)
testcpp:11:7: pasting "#" and "2" does not give a valid preprocessing token

You can always do it like this (you have to pass "#2" as argument):
#define mv_dest(dest, reg) move dest, reg;
mv_dest(#2, d1)
]

C preprocessor is *not* a text processor, and might prove unsuitable
for your task. My advice would be rather stay with your in-house
solution, or look for a regular text processor (many would point to m4).

--
Stan Tobias
sed 's/[A-Z]//g' to email
Nov 14 '05 #2
hello,
We're using in-house C pre processor for Assembly development.
We'd like to move to a standard "C" pre processor (such as gcc's "cpp"). First of all welcome to gcc :)
However we have the following problem:
Out assembly code have the following syntax:
move #2, d1;

How can I write a macro that will produce the above line?
If I try:
#define mv(reg) move #2, reg;
I get (for cpp -E):
f:1:23: '#' is not followed by a macro parameter

I've tried with ## and \# but it doesn't work.
Is there a way around this? i think ## should work. The following line compiles well with my gcc

#define mv(reg) move ##2, reg

the details of my gcc are as follows -
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --with-system-zlib --enable-__cxa_atexit
--host=i386-redhat-linux
Thread model: posix
gcc version 3.3.2 20031022 (Red Hat Linux 3.3.2-1)

I hope that you find the information useful
Thanks.
Miki

Nov 14 '05 #3

On Mon, 27 Sep 2004, Miki Tebeka wrote:

We're using in-house C pre processor for Assembly development.
We'd like to move to a standard "C" pre processor (such as gcc's "cpp").

However we have the following problem:
Out assembly code have the following syntax:
move #2, d1;
From the GNU 'cpp' manpage: The C preprocessor is intended to be used only with C, C++, and Objec-
tive-C source code. In the past, it has been abused as a general text
processor. It will choke on input which does not obey C's lexical
rules. For example, apostrophes will be interpreted as the beginning
of character constants, and cause errors. Also, you cannot rely on it
preserving characteristics of the input which are not significant to C-
family languages. If a Makefile is preprocessed, all the hard tabs
will be removed, and the Makefile will not work.


In short: You can't use 'cpp' to process assembly code; it won't work.
'cpp' only processes C and C++ code, and occasionally things that look
something like C or C++.

What you want is a general macro processor. Look up 'm4', which is
also available from GNU. Also try asking in comp.programming or
comp.lang.misc, where discussion of that kind of thing is on-topic.

HTH,
-Arthur

Nov 14 '05 #4
iolotusbobo wrote:
i think ## should work. The following line compiles well with my gcc

#define mv(reg) move ##2, reg


This does not do what you think. Here's the preprocessor output on mv(r5):

move2, r5

You simply pasted together the tokens "move" and "2" with the
token-pasting operator ##.
--
Derrick Coetzee
I grant this newsgroup posting into the public domain. I disclaim all
express or implied warranty and all liability. I am not a professional.
Nov 14 '05 #5
S.Tobias wrote:
Try this:

#define HASH2 #2
#define mv(reg) move HASH2, reg;


or:

#define HASH() HASH_I
#define HASH_I #

#define mv(reg) move HASH()2, reg;

Regards,
Paul Mensonides
Nov 14 '05 #6
Paul Mensonides <le******@comcast.net> wrote:
S.Tobias wrote:
Try this:

#define HASH2 #2
#define mv(reg) move HASH2, reg;
or: #define HASH() HASH_I
#define HASH_I # #define mv(reg) move HASH()2, reg;


But with gcc cpp this yields:
move # 2, reg ;
^^ we probably don't want these spaces
I guess that a preprocessor needn't put them here, because
'#' and '2' are distinguishable as tokens, but may;
anyway, text output from cpp is not what the Std defines.

Regards!

--
Stan Tobias
sed 's/[A-Z]//g' to email
Nov 14 '05 #7

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

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
2
by: Asad | last post by:
I have a form on a page that has several textareas, and textboxes inside a table (so the table containing the textboxes is also inside the FORM tag). I want to replace the textareas with simple...
15
by: Matthias Hullin | last post by:
Hi, I'm programming some PHP discussion board that is supposed to appear inside the content area of a proprietary CMS. As I need some more styles than the standard stylesheet provides, I just...
7
by: Peter Ammon | last post by:
K.N. King's book "C Programming: A Modern Approach" gives this exercise in chapter 14, which is about the preprocessor: The following macro has a subtle problem: #define ABS(a)...
20
by: Srinivas Mudireddy | last post by:
Hi, I am facing a problem with trying to conditionally compile inside a macro. I have a macro #define SET_VAL(x, y) ((x) = *(y)) But the problem is y can be NULL in which case I want to set...
5
by: krbyxtrm | last post by:
Hi is there a way to 'manage' function execution using macros? #define MY_CALL_MACRO(MacroName) { g_MacroStack.push_back(MacroName); <some code here...>} such that when i use the...
0
by: hartliec | last post by:
I would like to execute a Access 2002 Macro (TransferText) using ASP. Any ideas? This is what I have so far.. Page 1 *****accessmacro.asp************ <html><body> <% strDbName = 'Put...
2
by: talkaboutquality | last post by:
Need to define a macro as, say, #ifdef NEED_FUNCTION foo(x) #else #endif
1
by: Winks | last post by:
I would like to create a button that opens Outlook and puts some text in the body of the email. I don't need any attachments, just some text in the body. I've accomplished the ability to create...
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...
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
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,...
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...
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,...

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.