Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Maybe a MSVC 6 compiler bug with standard types conversion ?

Author: Dieter Buerssner

Date: 23:32:05 02/05/05

Go up one level in this thread


On February 05, 2005 at 21:40:42, Daniel Mehrmannn wrote:

>from time to time i just compile my engine with "post all errors" flags.

Highest warning level produces many useless warnings for me with some compilers.
Gcc is ok, MSVC and ICC give tons of stupid warnings, that really are not
appropriate at the point given. I ignore them.

>I only wanna ask here if its known that the MS compiler have maybe problems
>with casting standard c types if we used this types as a pointer in the function
>head ?
>
>Example:
>May we define a unsigend char in a function and give the adress to another
>function.

Yes, you can give the adress to a called function without any problem. Of course
returning the adress will typically be wrong (unless the unsigned char is
static). Your code is correct. I would not add a cast, to stop the compiler
warning.

>#define SET_BIT_1 1
>#define SET_BIT_2 2
>
>void
>DoSomeThingWith_i(unsigend char *i)
>{
>     *i = SET_BIT_1 | SET_BIT_2;
>
>}
>
>void
>example()
>{
>     unsigned char i = 0;

No need to initialize i here with 0. Sometimes compilers give a warning: "i
might be uninitialized". I would typically not initialize it, just to stop the
compiler complaining.

>     DoSomeThingWith_i(&i);
>}
>
>And here my complier give a cast waring out by line: *i = SET_BIT_1 | SET_BIT_2;

Perhaps, it would give the same warning for a plain unsigned char assignment (no
indirection via pointer)? SET_BIT_1 | SET_BIT_2 will be calculated in int, not
in unsigned char, due to C rules. But in this case, it does not make any
difference of course.

Regards,
Dieter



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.