problem with setjmp

From: candy (candy_init_at_yahoo.com)
Date: 11/28/04


Date: 28 Nov 2004 08:37:01 -0800

hi all,

Consider the following C code:

void funct(){
}

int main(){
  int x;
  x=funct;
  printf("%x\n",x);
  return 0;
}

 It prints the address of the function funct().It means that
the function funct() is in the process stack even before it is
called.So,it should be safe to call setjmp in the function
funct() in the following way:

jmp_buf env;

int funct(){

  if(setjmp(env)==1)
    printf("called by longjmp\n");
   return 0;
}

int main(void){

  funct();
  longjmp(env,1);
  return 0;
}

On execution,the above program crashes.Can anybody please tell me
that what is the problem.

Thanks.



Relevant Pages

  • Re: problem with setjmp
    ... > int main{ ... This is both a constraint violation and produces undefined behavior. ... > funct() in the following way: ... C and read how setjmp() and longjmpwork. ...
    (comp.lang.c)
  • Re: problem with setjmp
    ... >int main{ ... > It prints the address of the function funct(). ... Even where there is a "process stack", ... The call to longjmp() attempts to jump into a function activation ...
    (comp.lang.c)
  • Re: Using [ebp-8] as a memory location
    ... int main ... funct(*ptr); // trying to change the value of *ptr. ... global _funct ... The code snippet is for the NASM assembler. ...
    (comp.lang.asm.x86)
  • Re: #defines
    ... creates a context switching as in the case of normal functions. ... In this case 'int i' was not declared in funct but it works. ...
    (comp.lang.c)
  • Re: Lotto 7/45
    ... I found an algorithm to generate a random case, ... like calling rand() 7 times, so it seems churlish to call it another ... The problem is that if int is 64 bits, ... may well be safe in C90 -- as I say, ...
    (comp.programming)