473,799 Members | 3,185 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

longjmp vs goto

Can someone kindly clarify the distinction between long jumps and
gotos? Why is one frowned upon and not the other? Is there really
any situation where use of longjmp becomes inevitable? A real-life
code snippet would surely help.

Regards,
Nimmi
Nov 14 '05
22 6071
"Dan Pop" <Da*****@cern.c h> wrote in message
news:bv******** **@sunnews.cern .ch...

As usual, there is no substitute for knowing what you're doing and
longjmp is not the right thing when malloc and/or fopen (may) have been
called (without) the corresponding free/fclose calls between the
invocation of setjmp and the longjmp call.


Throw va_start/va_end into there too.

--
Peter
Nov 14 '05 #21
# But doesn't that mean that each function doesn't have to be reentrant?
# So what I understand is that if I was busy calling longjump from my
# program, and then I would get into my signal handler and call longjump

All of which is irrelevant if the signal isn't in a standard library
function. If the hardware probe function doesn't use any standard library
function directly or indirectly and doesn't depend on unsafe global
variables, then a longjmp on a signal is perfectly safe.

--
Derk Gwen http://derkgwen.250free.com/html/index.html
I love the smell of commerce in the morning.
Nov 14 '05 #22


Peter Nilsson wrote:
"Dan Pop" <Da*****@cern.c h> wrote in message
news:bv******* ***@sunnews.cer n.ch...

As usual, there is no substitute for knowing what you're doing and
longjmp is not the right thing when malloc and/or fopen (may) have been
called (without) the corresponding free/fclose calls between the
invocation of setjmp and the longjmp call.


Throw va_start/va_end into there too.

--
Peter


In a universe far-far away (circa 1979) there was a boy genius who would
gladly help
you debug your code under three conditions:

1. You didnt't use signals.
2. Use didn't use setjmp() and longjmp()
3. You never,ever used unadorned scanf()

His rationale for the first two was that if you had the brass to use
them, you had BETTER know
what you're doing and thus had already shown that you didn't need his help.
It ain't for newbies, folks.

I'll leave it as an exercise to the reader to determine his rationale
for the third.

Note: that va_start/va_end were not part of the package at that time,
although I would
presume he would have included them if they had been.
Nov 14 '05 #23

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

Similar topics

2
2296
by: Thomas Baruchel | last post by:
Hi, wondering about: func1: setjmp() ; func2(); func2: {FILE *f; f = fopen(); func3(); fclose(f)} func3 : if() longjmp; else return; Note that FILE *fis a local variable in func2.
12
3330
by: Michael B Allen | last post by:
Should setjmp/longjmp really be used in a fast mundane ANSI C piece of code? Or is it frowned apon like goto? I have a need but I don't want to use something that is costly, isn't supported consistenly, or something that might pull in exotic text segments, etc. Specifically I have a hairly algorithm loop that uses what is currently a macro V. Here's a snipplet: for (k = d; k >= -d; k -= 2) { if (k == -d || (k != d && V(fwd, m, k - 1)...
2
2126
by: Ravi Uday | last post by:
Hi, Can anyone explain me why do we use setjmp and longjump functions. I read through the manual pages/doc but wasnt able to get a clear picture of the same. Any small example illustrating these would be real helping. Also, what happens when one jumps from one process/task to other, even though it is OT can anybody clear this concept.
4
2127
by: Jrferguson | last post by:
I have a C program that I am trying to port to a Motorola 68k based system. It makes use of setjmp and longjmp which are not supported by my C compiler. I understand the general principle behind setjmp/longjmp, but I am somewhat lost in the detail of how to actually implement this in assembler. (My compiler supports in-line assembler which I hope will prove usefull). I will be very gratefull for any help or pointers with this problem. I am...
2
1414
by: Jerald Fijerald | last post by:
Hello. I'm trying to find an elegant way to longjmp to the callee (aka "generators for C") So far I've come to this experimental program (gcc only as it uses __builtin_frame_address, although we can do without it): ====================================================================== /* longjmp to the callee */
8
2424
by: Zheng Da | last post by:
I wrote a simple one as follow: typedef struct __myjmp_buf { int efp; int epc; }myjmp_buf; int mysetjmp(myjmp_buf env) {
6
3229
by: Clausfor | last post by:
Hello, I have a problem with restoring variables in the setjmp/longjmp functions: K&R2 for longjmp says: "Accessible objects have the same value they had when longjmp was called, except for automatic non volatile variables of the function invoking setjmp, these will be undefined if modified after the setjmp call"
0
1280
by: sh.vipin | last post by:
Based on some study about setjmp / longjmp I have developed following notions about setjmp / longjmp . Would like to get feedback on them ?? Q1. Is there any point in keeping jmp_buf variable local to a function. Because if the variable is local then any other function can not return to this state (without using any other global variable) because jmp_buf variable is local to caller function. And if doing error handling within a function...
0
9685
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9538
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10470
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10247
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10214
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7561
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6803
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5583
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4135
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.