#151669 - HyperHacker - Mon Mar 03, 2008 3:00 am
With the latest libNDS (unless the DKP updater is out of date) I'm getting warnings that I didn't get before about incompatible types when I pass (for example) u32 to something expecting unsigned int. Aren't they the same thing?
_________________
I'm a PSP hacker now, but I still <3 DS.
#151670 - Dwedit - Mon Mar 03, 2008 3:16 am
You sure it's not some other modifier that's causing the error? Unsigned int is most definitely the exact same thing as u32.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."
#151671 - HyperHacker - Mon Mar 03, 2008 3:20 am
I can't see what it would be. It's actually any time I use a pointer to one of these, e.g.:
Quote: |
f:/dev/ds/src/bootmenu2/arm7/source/arm7.c:968: warning: passing argument 1 of 'touchReadTemperature' from incompatible pointer type
f:/dev/ds/src/bootmenu2/arm9/source/menus.c:652: warning: format '%u' expects type 'unsigned int', but argument 3 has type 'u32' |
touchReadTemperature is defined: Code: |
uint32 touchReadTemperature(int * t1, int * t2); |
and the line in question does this: Code: |
s32 t1=0, t2=0;
[...]
IPC2->Temperature = touchReadTemperature(&t1, &t2); |
It complains about both arguments, I just didn't see the need to quote both warnings.
_________________
I'm a PSP hacker now, but I still <3 DS.
#151674 - tepples - Mon Mar 03, 2008 4:31 am
I seem to remember reading that newer libnds redefined u32 in terms of uint32_t of C99's stdint.h, which Newlib defines as unsigned long int, not unsigned int.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#151677 - HyperHacker - Mon Mar 03, 2008 4:42 am
Anything I can do about that then?
_________________
I'm a PSP hacker now, but I still <3 DS.
#151690 - nanou - Mon Mar 03, 2008 10:29 am
Maybe switch to using unsigned int?
If that's not cool, you could always ignore the warnings or recast it manually when making the call (I prefer the latter.)
Or do you want to fix the definitions and maybe recompile the libs?
_________________
- nanou
#151691 - HyperHacker - Mon Mar 03, 2008 10:40 am
Recasting just gives different warnings, and changing the libs doesn't seem like a good idea. Switching would mean having to change the type of nearly every variable in the program and break the habit of using those types (which are far more convenient), which is silly given they're supposed to be compatible anyway.
_________________
I'm a PSP hacker now, but I still <3 DS.
#151692 - wintermute - Mon Mar 03, 2008 11:25 am
What I've done for the next toolchain iteration is make stdint.h prefer int to long when both are 32 bit. The patch fragment follows
Code: |
diff -Nbaur newlib-1.15.0/newlib/libc/include/stdint.h newlib-1.15.0-new/newlib/libc/include/stdint.h
--- newlib-1.15.0/newlib/libc/include/stdint.h Wed Aug 16 22:39:43 2006
+++ newlib-1.15.0-new/newlib/libc/include/stdint.h Tue Jan 8 04:11:30 2008
@@ -79,13 +79,13 @@
#endif
#endif
-#if __have_long32
-typedef signed long int32_t;
-typedef unsigned long uint32_t;
-#define __int32_t_defined 1
-#elif __STDINT_EXP(INT_MAX) == 0x7fffffffL
+#if __STDINT_EXP(INT_MAX) == 0x7fffffffL
typedef signed int int32_t;
typedef unsigned int uint32_t;
+#define __int32_t_defined 1
+#elif __have_long32
+typedef signed long int32_t;
+typedef unsigned long uint32_t;
#define __int32_t_defined 1
#elif __STDINT_EXP(SHRT_MAX) == 0x7fffffffL
typedef signed short int32_t;
|
You could save this as stdint.patch somewhere then open an msys console & cd to $(DEVKITARM)/arm-eabi. From there use the following command line to apply the patch.
Code: |
patch -p3 -i <path to >/stdint.patch
|
This will be already applied in devkitARM r22 which is currently waiting for me to figure out how to make the GBA linkscripts work with the latest binutils iteration.
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog
#151693 - nanou - Mon Mar 03, 2008 12:49 pm
HyperHacker wrote: |
Recasting just gives different warnings, |
It's been a long while since I've had to work with really messy type conflicts in a similar situation. Does recasting through void clear the warnings? IIRC it won't mind if you recast to or from void. I think that's what I ended up doing.
OTOH, wintermute's solution is best: have the right people fix the libs and forget about it. Though if you haven't applied the patch yet it might be worth working it out so you'll know for the future.
_________________
- nanou
#151694 - nipil - Mon Mar 03, 2008 1:22 pm
Use %lu instead of %u.
I think your problem is not about typecasting, but more about the type
expectation of the *printf functions : ie you're passing a u32 which is
defined as long something, *printf wants a long-something specifier.
From the wikipedia :
Quote: |
Length can be omitted or be any of:
* 'hh' : For integer types, causes printf to expect an int sized integer argument which was promoted from a char.
* 'h' : For integer types, causes printf to expect a int sized integer argument which was promoted from a short.
* 'l' : (ell) For integer types, causes printf to expect a long sized integer argument.
* 'll' : (ell ell) For integer types, causes printf to expect a long long sized integer argument.
* 'L' : For floating point types, causes printf to expect a long double argument.
* 'z' : For integer types, causes printf to expect a size_t sized integer argument.
* 'j' : For integer types, causes printf to expect a intmax_t sized integer argument.
* 't' : For integer types, causes printf to expect a ptrdiff_t sized integer argument. |
_________________
NDS Lite Gold/Silver, MK5/R4DS, MSI PC54G2, D-Link DI-624
#152069 - HyperHacker - Sun Mar 09, 2008 6:39 am
OK, that patch did the job, although I got a warning about it terminating partway through the file.
Related question, how do you "pack" a structure? I've got one that should be 56 bytes but is being padded out to 60. Everything I've tried or seen on Google doesn't work. __attribute__((packed)) and __attribute__((__packed__)) are ignored (it even tells me so), #pragma pack(1) appears to work but there's no way to restore it (pack, pack(0), pack(), pack(pop) etc are all ignored).
_________________
I'm a PSP hacker now, but I still <3 DS.
#152077 - tepples - Sun Mar 09, 2008 1:44 pm
HyperHacker wrote: |
OK, that patch did the job, although I got a warning about it terminating partway through the file. Related question, how do you "pack" a structure? |
If you carefully arrange the fields in the struct, you won't need packing. Can you paste the structure definition so that we can try to optimize the order of fields? Or are you trying to use fread() to read user-provided binary files in a de facto standard file format that you can't change?
Quote: |
I've got one that should be 56 bytes but is being padded out to 60. Everything I've tried or seen on Google doesn't work. __attribute__((packed)) and __attribute__((__packed__)) are ignored (it even tells me so) |
IBM lists a possible solution.
Will split soon.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.