• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Don't understand this compiler warning
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Don't understand this compiler warning


  • Subject: Re: Don't understand this compiler warning
  • From: "Justin C. Walker" <email@hidden>
  • Date: Tue, 28 Jun 2005 06:54:45 -0700


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).

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
  • Follow-Ups:
    • Re: Don't understand this compiler warning
      • From: Markus Ruggiero <email@hidden>
References: 
 >Don't understand this compiler warning (From: Markus Ruggiero <email@hidden>)

  • Prev by Date: Don't understand this compiler warning
  • Next by Date: Can't get Subversion working with XCode 2.1
  • Previous by thread: Don't understand this compiler warning
  • Next by thread: Re: Don't understand this compiler warning
  • Index(es):
    • Date
    • Thread