Quality RTOS & Embedded Software

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




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) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists