This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Macro Labels in local scope: Works with g++ but breaks with gcc


On Fri, 14 Nov 2003, Rama Singh wrote:

GCC has a provision for generating unique labels.

You should read the gcc manual.

Toshi

> Hi,
> I s there a way to implement laels in macros for local
> scope using GCC. Attached is a code snippet that I am
> using in my application. The problem is that I am
> using a Macro in which there are labels and jumps to
> these labels. Now when this macro is expanded, it
> gives duplicate label error. 
> This code runs fine with g++ but breaks with gcc. Is
> it a specific behaviour of the C standard?
> 
> I have tried it on g++ 2.96 and 3.2 running on a RH
> 7.2
> 
> If this is a bug, has it been fixed in the latest
> release of gcc?
> 
> //====Copy Here=========================
> #ifdef __cplusplus
> #include <iostream>
> #else 
> #include <stdio.h>
> #endif 
> #include <assert.h>
> 
> 
> #define CHECK_MACRO(pA,B,C) \
> {\
> 	__label__ lbl_1;\
> 	__label__ lbl_2;\
> 	__label__ lbl_3;\
> \
> 	*pA = 0; \
> \
> lbl_1: \
> 	if(B>10) { \
> 		goto lbl_2; \
> 	} \
> 	*pA = 10; \
> 	goto lbl_3; \
> lbl_2:  \
> 	*pA = B+10; \
> 	if (*pA < 7) \
> 		goto lbl_1; \
> lbl_3: \
> 	*pA = C+100; \
> }
> 
> // Test code for checking the macro operation
> int main(int argc, char *argv[])
> {
> 	short	data1;
> 	short	data2;
> 	short	data3;
> 
> 	printf(" Test code\n");
> 
> 	data2 = -2; 
> 	data3 = 12; 
> 	CHECK_MACRO(&data1, data2, data3);
> 	printf(" data1 %d, data2 %d, data3 %d \n", data1,
> data2, data3);
> 
> 	data2 = -7; 
> 	data3 = 9; 
> 	CHECK_MACRO(&data1, data2, data3);
> 	printf(" data1 %d, data2 %d, data3 %d \n", data1,
> data2, data3);
> 
> 	printf (" Test completed successfully! \n");
> }
> ==Till Here==============
> 
> ________________________________________________________________________
> Yahoo! India Mobile: Download the latest polyphonic ringtones.
> Go to http://in.mobile.yahoo.com
> 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]