C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

JPEG/setjmp always fails

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
St?phane Vaxelaire
Guest





PostPosted: Sat Sep 27, 2003 2:46 pm    Post subject: JPEG/setjmp always fails Reply with quote



Hi,

I'm working on a project where we had a function that loads a jpeg
file.
I moved that function into a class that handles images without
modifications but
now setjmp never returns 0 anymore under win32.
The code still works under Linux and MacOS X though.

Any idea why setjmp would always return something !=0 only under win32
??

Any help is greatly appreciated, thanks.

Here is the beginning code (full file at
http://ewave.homelinux.org/vegastrike/vsimage.cpp) :

my_error_mgr jerr;
JSAMPARRAY row_pointers=NULL;// Output row buffer

cinfo.err = jpeg_std_error(&jerr.pub);
jerr.pub.error_exit = my_error_exit;

int val;

if ((val=setjmp(jerr.setjmp_buffer)))
{
.......

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Jack Klein
Guest





PostPosted: Sun Sep 28, 2003 10:25 am    Post subject: Re: JPEG/setjmp always fails Reply with quote



On 27 Sep 2003 10:46:34 -0400, [email]surfdargent (AT) free (DOT) fr[/email] (St?phane
Vaxelaire) wrote in comp.lang.c++.moderated:

Quote:
Hi,

I'm working on a project where we had a function that loads a jpeg
file.
I moved that function into a class that handles images without
modifications but
now setjmp never returns 0 anymore under win32.
The code still works under Linux and MacOS X though.

Any idea why setjmp would always return something !=0 only under win32
??

Any help is greatly appreciated, thanks.

Here is the beginning code (full file at
http://ewave.homelinux.org/vegastrike/vsimage.cpp) :

my_error_mgr jerr;
JSAMPARRAY row_pointers=NULL;// Output row buffer

cinfo.err = jpeg_std_error(&jerr.pub);
jerr.pub.error_exit = my_error_exit;

int val;

if ((val=setjmp(jerr.setjmp_buffer)))
{

You are calling setjmp in a manner not guaranteed to have defined
behavior. Note that the C++ standard does not specifically define the
operation of setjmp(), but refers to the C standard, which states:

========
An invocation of the setjmp macro shall appear only in one of the
following contexts:

— the entire controlling expression of a selection or iteration
statement;

— one operand of a relational or equality operator with the other
operand an integer constant expression, with the resulting expression
being the entire controlling expression of a selection or iteration
statement;

— the operand of a unary ! operator with the resulting expression
being the entire controlling expression of a selection or iteration
statement; or

— the entire expression of an expression statement (possibly cast to
void).

5 If the invocation appears in any other context, the behavior is
undefined.
========

Now this may not be your problem, but assigning the value returned by
setjmp() results in undefined behavior under the language standard.

If you must save the actual value returned without invoking undefined
behavior, you need to use a switch statement:

switch (setjmp(jerr.setjmp_buffer))
{
case 0:
val = 0;
break;

case SOME_VALUE:
val = SOME_VALUE;
break;

// etc.
}

If you eliminate the assignment one way or another and your program
still has the error, you have a valid complaint, assuming you have all
current service packs installed. If the program works with the
assignment eliminated, the compiler is within its rights, no matter
how inconvenient it may seem to you.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.