compiler warning in tasks.c

enken wrote on Sunday, January 10, 2010:

I am getting the following compiler warning twice on line 422 in tasks.c
“cast from pointer to integer of different size”

The line is:
pxTopOfStack = ( portSTACK_TYPE * ) ( ( ( unsigned long ) pxTopOfStack ) & ( ( unsigned long ) ~portBYTE_ALIGNMENT_MASK  ) );

compiled using mspgcc 3.2.3 and portBYTE_ALIGNMENT = 2

I’ve seen this warning since 6.0.0, still there in 6.0.2. Any pointers as to what could be done, is the error on my side/compiler?

rtel wrote on Monday, January 11, 2010:

I think this must be complaining about casting from pxTopOfStack to unsigned long.  Presumably pxTopOfStack is of type portSTACK_TYPE *, which is unsigned short *.

Is the code working ok if you ignore the warning?


enken wrote on Tuesday, January 12, 2010:

Yes, it’s just a simple warning, tasks seem to execute fine. I’d like to get rid of it however, or at least understand why no one else seems to get this warning.

PS… looking forward to my PDF books…

enken wrote on Tuesday, January 12, 2010:

Hm! My first FreeRTOS report! There is a duplication of “#define tskIDLE_PRIORITY”

The first is in task.h : 127
The second is in tasks.c : 75

Hardly critical, but hey! A dupe’s a dupe. Also shouldn’t it be “task.c” instead of “tasks.c”, to keep in line with the rest of your naming convention?

rtel wrote on Wednesday, January 13, 2010:

Hmm.  That looks like a ‘temporary’ line that should have been removed.  I have deleted the one in tasks.c.  Thanks for pointing that out.

With regard to the header file name - yes that was a mistake that was made many, many years ago and is annoying.  I have always left it because to change it would break peoples code.

I presume you got your PDF files?


lamming wrote on Sunday, January 17, 2010:

I’m getting the same error message with AVR Studio for Mega128.
Is there some way to make it shut up please?

kevinroland wrote on Tuesday, September 21, 2010:

I made the following change to tasks.c.  It preserves the “unsigned long” type used by the code.  (Alternatively, I think “unsigned long” could be replace by uintptr_t if you rely on the C99 standard.)

<somewhere near top of file>
 * Union to allow application of alignment mask to "top of stack"
 * pointer without compiler warnings.
typedef union topOfStackConversion
	portSTACK_TYPE *pxTopOfStack;
	unsigned long ulTopOfStack;
} topOfStackConv;
<inside of xTaskGenericCreate>
topOfStackConv xTopOfStack;
#if( portSTACK_GROWTH < 0 )
	xTopOfStack.pxTopOfStack = pxNewTCB->pxStack + ( usStackDepth - 1 );
	xTopOfStack.ulTopOfStack &= ( unsigned long ) ~portBYTE_ALIGNMENT_MASK;
	pxTopOfStack = xTopOfStack.pxTopOfStack;


kevinroland wrote on Tuesday, September 21, 2010:

I should add that I only tested this with the AVR GCC tools for an ATxmega128A1.  I did a brief search, but other than my original reference, I did not find any guarantees about the alignment of the different types in the union.  I don’t suggest you blindly use this without testing it on your specific platform.