Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT




Loading

compiler warning in tasks.c

Posted by enken on 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?

RE: compiler warning in tasks.c

Posted by Richard on 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?

Regards.

RE: compiler warning in tasks.c

Posted by enken on 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...

RE: compiler warning in tasks.c

Posted by enken on 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?

RE: compiler warning in tasks.c

Posted by Richard on 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?

Regards.

RE: compiler warning in tasks.c

Posted by Mik Lamming on January 17, 2010
Richard,
I'm getting the same error message with AVR Studio for Mega128.
Is there some way to make it shut up please?

RE: compiler warning in tasks.c

Posted by kevin on 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.)



/*
* 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;


topOfStackConv xTopOfStack;
...

#if( portSTACK_GROWTH < 0 )
{
xTopOfStack.pxTopOfStack = pxNewTCB->pxStack + ( usStackDepth - 1 );
xTopOfStack.ulTopOfStack &= ( unsigned long ) ~portBYTE_ALIGNMENT_MASK;
pxTopOfStack = xTopOfStack.pxTopOfStack;
}
#else


Reference:https://www.securecoding.cert.org/confluence/display/cplusplus/INT11-A.+Take+care+when+converting+from+pointer+to+integer+or+integer+to+pointer

RE: compiler warning in tasks.c

Posted by kevin on 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.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS