Hi Khalida, |
|
Re: Re: [c6x] strange problem while not prototyping!!
Hi all, I've had this problem as well, and found a useful compiler switch to help. If you add '-pdr' you'll get remarks from the compiler highlighing the 'implicit declaration' of those unprototyped functions. I think the c-standard assumes integer if not prototyped. I hooked on '-pdr' now - which has saved me a lot of time since! raj --- In , "tArAng" <tarangdadia@r...> wrote: > Hi Khalida, > > You are absolutely correct .. when I tried to return a float .. without prototyping that function .. i got some junk value. (Non repeatable junk).. > Then i prototyped it and got the correct float value as I shud get. > > Thanks a lot for ur comment. > > Best Regards, > > Tarang Dadia > > > On Sun, 02 May 2004 KHALIDA1@a... wrote : > >In a message dated 5/1/2004 4:59:48 PM Eastern Daylight Time, > >tarangdadia@r... writes: > >Hi All, > >I just bumped across this strange thing by mistake. Dont know exactly why > >this is happening. > > > >The thing is I am writing couple of functions in different file (other than > >where my main is) . I am including this file to my project folder and calling > >those functions. No where am I prototyping the functions, its just a > >definition. Even in the main file I am not including the function file its just in the > >same project . Compiler or the linker doesnt throw any errors or anything. And > >still the functions are being called and executed properly. Its not a problem > >to me, I m just curious as to how did it take care of not prototyping it and > >not declaring it as extern and stuff. > > > >Just to make more sense out of my writing , kindly follow the pseudo-code. > >Hi Tarang, > > BE VERY careful of the not prototyping your functions in CCS!!! This a > >big bug that took weeks of investigation in my code to figure out. When you > >don't prototype, the compiler is assuming default parameters. For example, if > >your unprototyped function returns a float, the compiler will assume an integer > >return value. Try this with one of your unprototyped functions and change it > >to return a float value, especially a fraction, and assign the returned value > >to some float variable in your calling function (main in your case). Build > >your project and step through your code. Step into your unprototyped function, > >check the value it is about to return, now step out of it and check if it is > >the same. I bet you its not! If it turns out, please let us know your > >finding for benefit of the group. > > > > Now I think the compiler can be set so it will be more strict and check > >for prototypes and generate an error if it finds unprototyped function calls > >(force ANSI C checking?). Unfortunately CCS default setup is without this > >restriction, so we are exposed to this danger in our projects, unless we take care > >of it by prototyping always. > > > >Regards, > >/Khalid |
Hey Raj, |
Tarang,
I use the compiler user guide in general for
these bits.
http://focus.ticom/lit/ug/spru187k/spru187k.pdf
and programmers guide
http://focus.ticom/lit/ug/spru198g/spru198g.pdf
In this case, there's not a huge
amount of detail on specifics of '-pdr', other than
that this causes the compiler to issue remarks (non-serious
warnings). I find these really useful and you can always switch them off
once you are happy.
Regards,
raj
|
Raj- > I use the compiler user guide in general for these bits. > > http://focus.ticom/lit/ug/spru187k/spru187k.pdf > > and programmers guide > > http://focus.ticom/lit/ug/spru198g/spru198g.pdf > > In this case, there's not a huge amount of detail on specifics of > '-pdr', other than that this causes the compiler to issue remarks > (non-serious warnings). I find these really useful and you can > always switch them off once you are happy. I would advise *always* keeping all warnings and remarks enabled. Anything at all that catches your eye could save you hours later. If a particular non-serious warning is supposed to be there, and you don't want to keep seeing it, you can suppress just that one by giving the warning number. -Jeff |