Monday, January 27, 2014

goto label inside of if statement

Newsgroup: comp.lang.c++

Subject: goto label inside of if statement

From: W Karas <wkaras@...>

Date: Thu, 23 Jan 2014 11:32:13 -0800 (PST)



I was surprised to find that this code:



struct A { A(); ~A(); };



void bar();



void foo(bool f)

{

if (0)

{

LAB: ;

}

else

{

A a;



if (f) goto LAB;



bar();

}

}



will compile without warnings using GCC 4.7.3, even with -Wall and -Wextra .



The point, in case you were wondering, would be a macro-based "named block" pseudo-construct, where the block could be exited from any depth of block nesting, for example:



#define BLOCK(NAME) if (0) { NAME: ; } else

#define EXITBLOCK(NAME) goto NAME;



struct A { A(); ~A(); };



void bar();



void foo(bool f)

{

BLOCK(XYZ)

{

A a;



if (f) EXITBLOCK(XYZ)



bar();

}

}







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1glcAEV

View all the progranning help forums at:

http://ift.tt/1dP9txN

No comments:

Post a Comment