Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Don't understand this compiler warning




On 28.06.2005, at 15:54, Justin C. Walker wrote:


On Jun 28, 2005, at 06:39 , Markus Ruggiero wrote:


Folks,

This is some very old private code (from the mid-80ies, pre ANSI-C) that I try to port to the Mac. The code isn't mine but is supposed to compile under Windows 3.x (!) with MSVisualStudio 4.

I have no clue what the compiler tries to tell me:

    auto unsigned long    lcl_l_flags = 0;

    lcl_l_flags = pgf_setdef_flag_(HYPHEN_PGF,
                                   DDIF_M_T_HYPHENATION_ALLOWED,
                                   DDIF_M_T_HYPHENATION_ALLOWED);

pgf_setdef_flag is a macro defined as follows:

    #define pgf_setdef_flag_(flag,val,def)                    \
        ( (!spgfp) ? lcl_l_flags |= def                    \
               : (spgfp->flags & flag) ? lcl_l_flags |= val        \
                           : 0                \
        )

Thus the above code after preprocessing looks like:

    lcl_l_flags = ( (!spgfp) ? lcl_l_flags |= 1 : (spgfp->flags & (0x02)) ? lcl_l_flags |= 1 : 0 );

And then the compiler says:
    warning: operation on 'lcl_l_flags' may be undefined


This is a warning, not an error.  It indicates something that the compiler (writer) thinks may be problematic, but then again, may be all right.

In your case, the warning is correct: the code as written can lead to unexpected behavior.

Since 'lcl_l_flags' is an automatic variable, it is allocated on the stack.  Because of that, the variable will retain whatever value resides at that location in memory (you don't initialize the variable at the beginning of your routine).

But I *do* init the variable! So still the question is open: what could be wrong with this code fragment? I know, warnings are not errors - and sometimes the compiler is just plain wrong and the code is OK. I am just curious as to why the compiler thinks there might be problems.

Thanks for any more insights

---markus---
 
Your macro "updates" the value of the variable by doing the equivalent of
      lcl_l_flags = lcl_l_flags | 1;

If you are only interested in the low-order bit of the variable, then this isn't a problem (the macro will set that to either 1 or 0).  Otherwise, your code may be wrong.

Regards,

Justin

--
Justin C. Walker, Curmudgeon at Large
Institute for General Semantics
-----------
My wife 'n kids 'n dog are gone,
I can't get Jesus on the phone,
But Ol' Milwaukee's Best is my best friend.
-----------


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden



Markus Ruggiero

rucotec consulting and technologies    email     mailto:email@hidden

rucotec GmbH                           web       http://www.rucotec.ch

Steinentorstrasse 8             

4051 Basel                             Mobile    +41 (0)79 508 4701

Switzerland                            Phone/Fax +41 (0)61 271 4990



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/xcode-users/email@hidden

This email sent to email@hidden

References: 
 >Don't understand this compiler warning (From: Markus Ruggiero <email@hidden>)
 >Re: Don't understand this compiler warning (From: "Justin C. Walker" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.