CW Compiler issue regarding integer size

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

CW Compiler issue regarding integer size

2,102 Views
badaboom
Contributor I
Hello,

I had a piece of code working for the MCF52335 with the panel setting "4-byte integers' checked.
After a while I decided to reduce the size to 2 bytes ( unchecking the checkbox). Of course I made a size check of the int's used, but some fine working code doesn't work any more. I've inserted a part of a dis-assembled file.

My question is: does anyone knows why the returning void* (from malloc) gets sign extended to a long when I use a 2byte int size. (ext.l d0) I've checked the size of the void*, which is always 4bytes, regardless the __fourbyteints__  setting.
In my code code the returning void* is casted to a TCB* which is also a 4byte sized pointer.

0x0000001A  0x4EB900000000         jsr      _malloc
0x00000020  0x48C0                        ext.l    d0

I hope anyone can help me out.

badaboom

Code:
// __fourbyteints__ = false

;  102: ERROR TaskManCreateTask( const char * const pszName, pTaskFunction *pFunctList, TASKPRIORITY Taskpriority )
 ;  103: {
 ;  104: TCB *pNewTask;
 ;  105: ERROR retValue;
 ;  106: 
 ;  107: int i = sizeof(TCB*); // just checking
;
0x00000000                    _TaskManCreateTask:
;                             TaskManCreateTask:
0x00000000  0x4FEFFFDC               lea      -36(a7),a7
0x00000004  0x48EF58C00010           movem.l  d6-d7/a3-a4/a6,16(a7)
;
;  108:  pNewTask = (TCB*)malloc(sizeof(TCB));
 ;  109: 
 ;
0x0000000A  0x7E60                   moveq    #96,d7
0x0000000C  0x266F0028               movea.l  40(a7),a3
0x00000010  0x286F002C               movea.l  44(a7),a4
0x00000014  0x1C2F0030               move.b   48(a7),d6
0x00000018  0x2E87                   move.l   d7,(a7)
0x0000001A  0x4EB900000000           jsr      _malloc
0x00000020  0x48C0                   ext.l    d0
0x00000022  0x2C40                   movea.l  d0,a6
;
;  110:  pNewTask->lCount = i;
 ;
0x00000024  0x7004                   moveq    #4,d0
0x00000026  0x2D40003C               move.l   d0,60(a6)



// __fourbyteints__ = true:

;  102: ERROR TaskManCreateTask( const char * const pszName, pTaskFunction *pFunctList, TASKPRIORITY Taskpriority )
 ;  103: {
 ;  104: TCB *pNewTask;
 ;  105: ERROR retValue;
 ;  106: 
 ;  107: int i = sizeof(TCB*);  // just checking
;
0x00000000                    _TaskManCreateTask:
;                             TaskManCreateTask:
0x00000000  0x4FEFFFD8               lea      -40(a7),a7
0x00000004  0x48EF58E00010           movem.l  d5-d7/a3-a4/a6,16(a7)
;
;  108:  pNewTask = (TCB*)malloc(sizeof(TCB));
 ;  109: 
 ;  110:  pNewTask->lCount = i;
 ;
0x0000000A  0x7C60                   moveq    #96,d6
0x0000000C  0x2E86                   move.l   d6,(a7)
0x0000000E  0x266F002C               movea.l  44(a7),a3
0x00000012  0x286F0030               movea.l  48(a7),a4
0x00000016  0x1A2F0034               move.b   52(a7),d5
0x0000001A  0x4EB900000000           jsr      _malloc
0x00000020  0x2F460008               move.l   d6,8(a7)
0x00000024  0x2C40                   movea.l  d0,a6
0x00000026  0x7C00                   moveq    #0,d6
0x00000028  0x7004                   moveq    #4,d0
0x0000002A  0x2F460004               move.l   d6,4(a7)
0x0000002E  0x2D40003C               move.l   d0,60(a6)

 


Labels (1)
0 Kudos
Reply
2 Replies

618 Views
CrasyCat
Specialist III
Hello
 
Did you include stdlib.h in the source file where you are using malloc?
If not, there is no prototype for the function malloc and the compiler will assume it returns an int (thus adding an ext.l instruction).
 
Additionally did you link against the appropriate ANSI library?
Please refer to the {Install}\Help\PDF\ColdFire_Build_Tools_Reference.pdf Chapter  "Coldfire RunTime Libraries", section
"MSL for Coldfire Development " -> "Using MSL Library for Coldfire".
 
In order to prevent this kind of issue in the future I would recommend you to activate the option "Require Function Prototype" in the C/C++ Language panel.
This way the compiler will generate an error message if you use a function and you did not define its prototype previously.
I hope this helps.
 
CrasyCat
0 Kudos
Reply

618 Views
badaboom
Contributor I
Hi Crasycat,

I didn't include the stdlib...
I'll keep the "require function prototypes"  checkbox checked!

Problem solved... thanx :smileyhappy:

0 Kudos
Reply