char & UBYTE
char & UBYTE
Are char and UBYTE interchangeable types ?
- if no what is the difference?
- if yes how get rid of those warnings complaining about signedness? (in an easy way)
- if no what is the difference?
- if yes how get rid of those warnings complaining about signedness? (in an easy way)
Re: char & UBYTE
Oooh, i wanna know too
People are dying.
Entire ecosystems are collapsing.
We are in the beginning of a mass extinction.
And all you can talk about is money and fairytales of eternal economic growth.
How dare you!
– Greta Thunberg
Entire ecosystems are collapsing.
We are in the beginning of a mass extinction.
And all you can talk about is money and fairytales of eternal economic growth.
How dare you!
– Greta Thunberg
Re: char & UBYTE
exec/types.h tells you all you need to know:
Code: Select all
typedef unsigned char UBYTE; /* unsigned 8-bit quantity */
- salass00
- AmigaOS Core Developer
- Posts: 530
- Joined: Sat Jun 18, 2011 3:12 pm
- Location: Finland
- Contact:
Re: char & UBYTE
UBYTE is always unsigned while char without signed or unsigned keyword can be either signed or unsigned depending on the compiler, the target system and what compiler options are used (f.e. gcc allows to force either signed or unsigned with -fsigned-char and -funsigned-char options).JosDuchIt wrote:Are char and UBYTE interchangeable types ?
- if no what is the difference?
Use casts.JosDuchIt wrote:- if yes how get rid of those warnings complaining about signedness? (in an easy way)
Re: char & UBYTE
@salass00
i'lll try that first as easy solution. There must be hundreds of signedness complaints in the source i am working on (gcview - btw it compiles and works allready better than the 68k version under OS4) so casts were in my mind the hard solution. I guess i'll use the gcc option giving me the least signedness complaints and standardise(using casts) on that definition of char.gcc allows to force either signed or unsigned with -fsigned-char and -funsigned-char options).
Re: char & UBYTE
@salass00
Using no -f option i have 203 signedness warnings
using -fsigned-char i have 384 signedness warnings
using -funsigned-char i have 203 signedness warnings
even using casts i don't get rid of the warnings notably in the example below in the 2 stccpy calls
i always have the warning
/// pointer targets in passing argument 1&2 of 'stccpy' differ in signedness
Tests :
1) without -f
2) - with -funsigned-char
3) no -f
but with the casts
I expected to get rid of the warning both in the case 2) and 3) ??
Using no -f option i have 203 signedness warnings
using -fsigned-char i have 384 signedness warnings
using -funsigned-char i have 203 signedness warnings
even using casts i don't get rid of the warnings notably in the example below in the 2 stccpy calls
i always have the warning
/// pointer targets in passing argument 1&2 of 'stccpy' differ in signedness
Code: Select all
struct Picture // every picture gets one ///was Picture
{
UBYTE path[260];
UBYTE alias[40]; // the given name of this picture
}
struct Picture *getpic (char *name, char *alias, struct Base *bs, SHORT mode)
{
struct Picture *pic, *bpic;
stccpy (pic->path, name, 255);
stccpy (pic->alias, strupr(alias), 35);
}
size_t stccpy (
char * dest,
const char * src,
size_t n)
{
char * ptr = dest;
while (n>1 && *src)
{
*ptr = *src;
ptr ++;
src ++;
n--;
}
*ptr++ = '\0';
return (ptr-dest);
}
1) without -f
2) - with -funsigned-char
3) no -f
but with the casts
Code: Select all
stccpy (pic->path, (UBYTE *)name, 255);
stccpy (pic->alias, (UBYTE *)strupr(alias), 35);
Re: char & UBYTE
Hi JosDuchIt,
I don't understand why you are using this code.
First, The struct Picture seems to be two filenames (path and alias ?), so why don't you use char path[260] or better char * and initialize during execution time.
Second, in getpic function, the pointer pic is not initialized so you must not believe in the results (if your code doesn't crash).
Third, you use a custom copy of one arry to another, why don't you use str???? functions in <string.h>.
Fourth, your cast can't work if you don't change the api of stccpy like stccpy (UBYTE*, UBYTE*, size_t).
YesCop
I don't understand why you are using this code.
First, The struct Picture seems to be two filenames (path and alias ?), so why don't you use char path[260] or better char * and initialize during execution time.
Second, in getpic function, the pointer pic is not initialized so you must not believe in the results (if your code doesn't crash).
Third, you use a custom copy of one arry to another, why don't you use str???? functions in <string.h>.
Fourth, your cast can't work if you don't change the api of stccpy like stccpy (UBYTE*, UBYTE*, size_t).
YesCop
- thomasrapp
- Posts: 310
- Joined: Sat Jun 18, 2011 11:22 pm
Re: char & UBYTE
A cast changes the type of the pointer, not the type of the function argument. If you have a pointer to UBYTE and a function which needs char, you need to cast to char, not the other way around.JosDuchIt wrote:but with the castsI expected to get rid of the warning both in the case 2) and 3) ??Code: Select all
stccpy (pic->path, (UBYTE *)name, 255); stccpy (pic->alias, (UBYTE *)strupr(alias), 35);
The right casts in your example were
Code: Select all
stccpy ((char *)pic->path, name, 255);
stccpy ((char *)pic->alias, strupr(alias), 35);
- salass00
- AmigaOS Core Developer
- Posts: 530
- Joined: Sat Jun 18, 2011 3:12 pm
- Location: Finland
- Contact:
Re: char & UBYTE
Better use TEXT type here instead of UBYTE. For string pointers you should use STRPTR (CONST_STRPTR for a constant string).JosDuchIt wrote:Code: Select all
struct Picture // every picture gets one ///was Picture { UBYTE path[260]; UBYTE alias[40]; // the given name of this picture }
Anyway if it's too annoying to fix all the pointer signedness warnings you can always disable them with "-Wno-pointer-sign".
Re: char & UBYTE
@yescop
as well the struct Picture as the getpic function were not completely shown.
Just what was enough to illustrate the problem.
The source compiles and the program (gcview) work
@salass00
thanks
I had to complete the casts to get rid of the warning concerning the 2d argument
as well the struct Picture as the getpic function were not completely shown.
Just what was enough to illustrate the problem.
The source compiles and the program (gcview) work
@salass00
thanks
I had to complete the casts to get rid of the warning concerning the 2d argument
Code: Select all
stccpy ((char *)pic->path, (const char *)name, 255);
stccpy ((char *)pic->alias, (const char *)strupr(alias), 35);