473,511 Members | 17,486 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Undefined symbol X..:(

1 New Member
I compiled this program in turbo c., it gave me error like undefined symbol 'x'., i thought it is a linker error., is it?

Expand|Select|Wrap|Line Numbers
  1. #define X (4+Y)
  2. #define Y (4+X)
  3. void main()
  4. {
  5. printf("%d",4*X+2);
  6. getchar();
  7. }
Dec 16 '11 #1
5 2536
donbock
2,426 Recognized Expert Top Contributor
What is your question?
What are you trying to accomplish?
Dec 16 '11 #2
weaknessforcats
9,208 Recognized Expert Moderator Expert
I think youo need to code:

Expand|Select|Wrap|Line Numbers
  1. #define X 4+Y
  2.  
Using () with a macro is interpreted as providing arguments to the macro.
Dec 16 '11 #3
Rabbit
12,516 Recognized Expert Moderator MVP
Doesn't that code create a circular reference?
Dec 16 '11 #4
weaknessforcats
9,208 Recognized Expert Moderator Expert
Yes it does. I didn't see that. Y will be undefined trying to define X.

I never use these things.
Dec 16 '11 #5
donbock
2,426 Recognized Expert Top Contributor
I ask again ... what do you wish to accomplish?

The pair of macro definitions appear designed to provoke an infinite regress of macro expansions. Why would you want to do that? As it happens, the C Standard won't let you.

From the C99 Standard (ISO/IEC 9899) ...
6.10.3.4 Rescanning and further replacement

1 After all parameters in the replacement list have been substituted and # and ## processing has taken place, all placemarker preprocessing tokens are removed. Then, the resulting preprocessing token sequence is rescanned, along with all subsequent preprocessing tokens of the source file, for more macro names to replace.

2 If the name of the macro being replaced is found during this scan of the replacement list (not including the rest of the source file's preprocessing tokens), it is not replaced. Furthermore, if any nested replacements encounter the name of the macro being replaced, it is not replaced. These nonreplaced macro name preprocessing tokens are no longer available for further replacement even if they are later (re)examined in contexts in which that macro name preprocessing token would otherwise have been replaced.
Consider this line from your program:
Expand|Select|Wrap|Line Numbers
  1. printf("%d",4*X+2);
"X" is recognized as a macro name. The line becomes this after replacement of X:
Expand|Select|Wrap|Line Numbers
  1. printf("%d",4*(4+Y)+2);
"Y" is recognized as a macro name. The line becomes this after replacement of Y:
Expand|Select|Wrap|Line Numbers
  1. printf("%d",4*(4+(4+X))+2);
That's the end of the line because paragraph 2 above prevents "X" from being recognized as a macro name again. Since this last "X" isn't a macro name it must be a variable name, but your program has no variable named X so you get an undefined symbol error.

By the way, the whitespace in the #defines between the macro names and the left parentheses prevent these from being considered function-like macros.
Dec 19 '11 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1754
by: pervinder | last post by:
Hi, I have a c++ application which depends on some other libs which uses stlport When i build the application, it works fine on sun/linux/hp platform. (provided the .a for the dependency libs) ...
0
1672
by: John Graat | last post by:
Hi all, I've built the STLport-462 library on AIX-4.3.3 using gcc-3.3.2. No errors during compilation. However, during linking the following error occurs: ld: 0711-317 ERROR: Undefined symbol:...
10
8037
by: eugene | last post by:
I'm trying to compile and run some c++ code to be called from Matlab (mex file) and I'm getting "Invalid MEX-file ... undefined symbol" error. Anybody knows where to look for solution? >>mex...
4
5711
by: r.nikhilk | last post by:
Hi, We are porting C++ applications from 32 bit to 64 bit on AIX platform. (The current version of AIX is 5.3 and xlC verison is 8.0). We are able to compile the applications by including the...
3
19232
by: Kenneth Kahl | last post by:
Hello, I would like to call a C++ programm out of Java with help of JNI. By the followed command I created a "shared library": g++ -shared -o libcalculate.so rechner.cpp When I create an...
8
17981
by: pavan734 | last post by:
Hello, Please excuse me as Iam not posting this to correct group. I have a parser code obtained from flex command. I have many other files. When I compile them Iam getting a message like:...
1
5530
by: yamitmehta | last post by:
When I compile to code using g++arm of VxWorks 5.5 and put it on my board i get the follwing undefined symbols:- Cpool and Csingleton are template classes. CPool has the static member...
1
4890
by: Justin Johnson | last post by:
Hello, I'm trying to build Python 2.5.0 on AIX 5.3 using IBM's compiler (VisualAge C++ Professional / C for AIX Compiler, Version 6). I run configure and make, but makes fails with undefined...
3
5316
by: sdeathstar | last post by:
I am working on IBM AIX machine and using XLC C++ complier version 8.0. 1) Able to compile the objects on AIX from C and C++ source code. 2) Able to create the libraries (combination of C & C++,...
1
6029
by: Michel Esber | last post by:
People, Environment: Linux AS4 I have just installed db2 v9.5 + Fixpak 2 on a machine that has db2 v8 up and running, but I am unable to create and instance: # ./db2icrt -a SERVER -p...
0
7245
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
7144
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
7356
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,...
1
7085
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
5671
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,...
1
5069
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...
0
4741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3214
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
449
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.