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

MACRO problem

I am sorry if this is not the concerned group.I am gettin following
problem while compiling this code:

#include<stdio.h>
#define PRI(item) printf ## (" ## item ## ");
void main()
{
PRI(hello)
}

While compiling i get

a.c:5:1: pasting "printf" and "(" does not give a valid preprocessing
token

What could be the possible problem with the macro defination?

Nov 15 '05 #1
3 1418
sorry for spaming your mailboxes....
i got the answer by searching the archives!

thanx

Nov 15 '05 #2
prophet wrote on 17/08/05 :
I am sorry if this is not the concerned group.I am gettin following
problem while compiling this code:

#include<stdio.h>
#define PRI(item) printf ## (" ## item ## ");
void main()
main() returns int. Always.
{
PRI(hello)
}

While compiling i get

a.c:5:1: pasting "printf" and "(" does not give a valid preprocessing
token
Sure, the code is not conforming.
What could be the possible problem with the macro defination?


You are making it too complicated (hence wrong).

Try that:

#include <stdio.h>

#define PRI(item) printf("%s\n", #item)

int main (void)
{
PRI (hello world);
return 0;
}

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

"There are 10 types of people in the world today;
those that understand binary, and those that dont."
Nov 15 '05 #3
prophet wrote:
I am sorry if this is not the concerned group.I am gettin following
problem while compiling this code:

#include<stdio.h>
#define PRI(item) printf ## (" ## item ## ");
void main()
{
PRI(hello)
}

While compiling i get

a.c:5:1: pasting "printf" and "(" does not give a valid preprocessing
token

What could be the possible problem with the macro defination?


The token paste operator is used to paste separate preprocessing tokens
into a single preprocessing token. It is typically used for generating
a single identifier from separate identifier parts. Both printf and (
are preprocessing tokens that become tokens in a later translation
phase. There is simply no preprocessing token consisting of an
identifier preceding a left parenthesis. The C Standard gives the details.

Thad

Nov 15 '05 #4

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

Similar topics

25
by: Andrew Dalke | last post by:
Here's a proposed Q&A for the FAQ based on a couple recent threads. Appropriate comments appreciated X.Y: Why doesn't Python have macros like in Lisp or Scheme? Before answering that, a...
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...
1
by: Giganews | last post by:
I have an Access 97 database in which I am running an Excel macro through automation. The macro in Excel is as follows: Worksheets("Sheet1").Protect Password:="****", DrawingObjects:=True,...
8
by: David | last post by:
Hi, I am using header file for driver so Can I define macro to call Kernel function ? What are the generatl rules for defining macro. - David
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...
10
by: Praveen.Kumar.SP | last post by:
Hi Could anyone solve the problem for the code below The Code: #include "stdio.h" #include "iostream.h" void Temp( int a, char* str,...)
6
by: Takeadoe | last post by:
Dear NG, Can someone assist me with writing the little code that is needed to run an update table query each time the database is opened? From what I've been able to glean from this group, the...
8
by: Net | last post by:
Hi Please help. I have a database which requires a message to come up when certain part numbers are added to it. I have solved part of this by using a conditional macro eg = 54125 and using a msg...
6
by: jason | last post by:
Hi, I learned my lesson about passing pointers, but now I have a question about macros. Why does the function work and the MACRO which is doing the same thing on the surface, does not work in...
36
by: sh.vipin | last post by:
how to make large macro paste the code as it is Problem Explanation '-- For example in the program below /* a.c - starts here */ #define DECL_VARS() \ unsigned int a0;\ unsigned int a1;\...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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.