473,403 Members | 2,284 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,403 software developers and data experts.

Labels and pointers

Is a label something like a pointer i can store in a variable ?

#include <stdio.h>

void foo(void *p)
{
printf("foo\n");
goto *p;
}

int main()
{
foo(&&L1); // ???????? Explain...
printf("bar\n"); // should not be executed ?
L1:
printf("quit\n");
return 0;
}

Can somebody elaborate on this code i found on the net ?...
gcc compiles it but the result is strange (MacIntel Leopard, gcc 4.0.0)

$ gcc prog.c -o prog
$ ./prog
foo
r is not present to run this program
bar
quit
$

Thanks,

-JG
Nov 23 '07 #1
3 3317
Jean-Guillaume Pyraksos wrote:
Is a label something like a pointer i can store in a variable ?

#include <stdio.h>

void foo(void *p)
{
printf("foo\n");
goto *p;
}

int main()
{
foo(&&L1); // ???????? Explain...
printf("bar\n"); // should not be executed ?
L1:
printf("quit\n");
return 0;
}

Can somebody elaborate on this code i found on the net ?...
It appears to use GCC specific extensions - try building it with the
options "-ansi -Wall -pedantic"
gcc compiles it but the result is strange (MacIntel Leopard, gcc 4.0.0)

$ gcc prog.c -o prog
$ ./prog
foo
r is not present to run this program
bar
quit
The reference manual page I found
(http://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html) says "You may
not use this mechanism to jump to code in a different function. If you
do that, totally unpredictable things will happen. The best way to avoid
this is to store the label address only in automatic variables and never
pass it as an argument."

So the code you quote is a) non-standard and b) broken even when && is
supported.

Nov 23 '07 #2
In article <wi**************************@malibu.unice.fr>,
Jean-Guillaume Pyraksos <wi****@hotmail.comwrote:
>Is a label something like a pointer i can store in a variable ?
As others have pointed out, only when using an extension like the
one that gcc provides.
>void foo(void *p)
{
printf("foo\n");
goto *p;
}

int main()
{
foo(&&L1); // ???????? Explain...
printf("bar\n"); // should not be executed ?
L1:
printf("quit\n");
return 0;
}
>Can somebody elaborate on this code i found on the net ?...
Again, as others have pointed out, this code is using the gcc
extension wrongly. You should only use it for jumps where a
normal jump to the location would be legal.
>gcc compiles it but the result is strange (MacIntel Leopard, gcc 4.0.0)

$ gcc prog.c -o prog
$ ./prog
foo
r is not present to run this program
bar
quit
My guess would be that the goto is "working", but because the function
foo is still active the format string "quit" is not in the right place
relative to the stack pointer, and instead it gets the end of some
other string (you can find what it probably is by googling for "is not
present to run this program"). It then executes main's return, but
because foo's stack frame is still there it returns to main, and
continues executing normally.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Nov 23 '07 #3
In article <8_******************************@comcast.com>,
Eric Sosman <es*****@ieee-dot-org.invalidwrote:
There are at least two reasons not to use this feature:
And there are also reasons to use it, though most people probably
won't encounter them. It seems quite in accord with the spirit of
C: no worse, for example, than setjmp()/longjmp().

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Nov 23 '07 #4

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

Similar topics

0
by: madeo | last post by:
hi, i'm looking for some script which would export address labels from a mysql db to pdf ... There's an exapmle, but i'm not able to convert it for using with mysql ... can anybody help? THX...
0
by: Brendan | last post by:
Hello, I am looking for any pointers on creating a Tree control which can render html snippets as labels. On each leaf of the tree I want to show text, but with more formatting than is...
2
by: DBQueen | last post by:
I have a database which will be printing out labels for SMALL test tubes (1/4" high). We have yet to find a reasonably-priced printer (labelwriter) which can effectively print this on ROLLS of...
6
by: DebbieG | last post by:
I am creating a database for a small department in a university. Each student in their database can have 2 mailing addresses. They wanted mailing labels pulling just the 1st address. No problem....
3
by: Grim Reaper | last post by:
I print mailing labels out of Access 2000 databases about 3 to 4 times a week. I have been having problems with one thing since I have been printing mailing labels. I print mailing labels by...
3
by: Grim Reaper | last post by:
I know this is probably an easy question, but I could not find/figure it out. Basically, I am printing mailing labels with a "Sorting/Grouping" section that groups the label types together....
6
by: Ron | last post by:
Hi, I know Access allows for easy construction of a report setup to print labels from a table/query, etc. I've done that one. It works pretty well for what I need. However, is there an...
0
by: keri | last post by:
Hi everyone, I have searched for info on this topic but have not found anything. Basically I have a db that posts appointments to outlook. I would like to be able to set all of the outlook...
0
by: xikom01 | last post by:
In this age, there is a lot of focus on the importance of "getting organized." There are even professional organizers for hire! Labels are a huge presence in the field of organization, because they...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
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...

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.