c++ - 'goto *foo' where foo is not a pointer. What is this? -


i playing around labels values , ended code.

int foo = 0; goto *foo; 

my c/c++ experience tells me *foo means dereference foo , won't compile because foo isn't pointer. compile. do?

gcc (ubuntu 4.9.2-0ubuntu1~12.04) 4.9.2, if important.

this known bug in gcc.

gcc has documented extension permits statement of form

goto *ptr; 

where ptr can expression of type void*. part of extension, applying unary && label name yields address of label, of type void*.

in example:

int foo = 0; goto *foo; 

foo of type int, not of type void*. int value can converted void*, explicit cast (except in special case of null pointer constant, not apply here).

the expression *foo correctly diagnosed error. , this:

goto *42; 

compiles without error (the generated machine code appears jump address 42, if i'm reading assembly code correctly).

a quick experiment indicates gcc generates same assembly code for

goto *42; 

as for

goto *(void*)42; 

the latter correct use of documented extension, , it's should if, reason, want jump address 42.

i've submitted bug report -- closed duplicate of this bug report, submitted in 2007.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -