Re: Stupid Compiler Tricks

From: Chuck Carson (chuck@EDEN.COM)
Date: 05/14/98


What OS and compiler is this?

Do you specifcally do anything with the variables
other than decalre them? There are some high
end compilers I believe that will omit varialbes if they
are not used anywhere in the code. (i think Sun's C
compiler can do this)

Try doing something simple with the varialbes like assigning
them some value in the function.

WC

-----Original Message-----
From: Sammy <samedi@DHC.NET>
To: CIRCLE@post.queensu.ca <CIRCLE@post.queensu.ca>
Date: Thursday, May 14, 1998 12:31 PM
Subject:  Stupid Compiler Tricks


>I've had the strangest thing happen to me while troubleshooting code
>recently.  I worked around it the first time, but tis is something that
>definitely needs fixing.
>
>What is happening is that I'm adding variables and code to an existing
>function (mobile_activity) which when compiled are completely ignored.
>Dong an "info locals" in gdb doesn't show my variables, and if I try to
>print them, I'm told there aren't any variables of that name in this
>context.  Strangely, the code shows up as expected when I "list" it, and
>if I pass the variables to functions, they're passed as 0.
>
>Here's a specific example.  I'm adding a dragon breath feature where I
>need to check each mob for it's dragon type, which I then pass to the
>dragon_breath() function if the mob is a dragon and fighting.  I'm using
>mob
>flags to set dragon type so I don't have to do anything with the mob
>files.
>
>In mobile_activity(), I added int dragon_type.  A little ways down,
>dragon_type is found by doing some bit shifting (I'm using 5 mob flag bits
>to allow for 31 dragon types).  If the dragon type is valid and the mob is
>fighting, I call dragon_breath(ch, dragon_type).
>
>Now, when this code runs, it acts as if dragon_type is always 0.  I've
>doublechecked my math to make sure it's correct.  GDB tells me dragon_type
>doesn't exist in mobile_activity.
>
>Any ideas about what's going on here?
>
>Sam
>
>
>     +------------------------------------------------------------+
>     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
>     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
>     +------------------------------------------------------------+


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/15/00 PST