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

length of integral portCHAR portSHORT...

Posted by supernewbie on August 14, 2009
Just wondering if all integral data type, such as portCHAR portSHORT portLONG are of fixed length. I supposed them to be yes. For example, portCHAR always 8bits, portSHORT always 16bit and portLONG always 32bits, is that true?
Thanks.

RE: length of integral portCHAR portSHORT...

Posted by dave m on August 14, 2009
Yes, within the compilation of any set of files that are to be linked together successfully, the data types will be of fixed (and equal) lengths. (That is, all portCHARs will be the same size, which is usually 8 bits. All portSHORTs will be the same size, and usually 16 bits, etc.)

The reason these are defined and used is so that you can change/fix things in one place if necessary. I'm not a C/C++ standards expert, but I think the rule on integral sizes is something like sizeof(char)<=sizeof(short)<=sizeof(int)<=sizeof(long). So theoretically, a char could be the same size as a long. This would cause problems for code that assumed that a short always has at least 16 bits. However, since FreeRTOS uses portSHORT everywhere, you can #define or typedef that to be whatever type causes the compiler to give you at least 16 bits.

RE: length of integral portCHAR portSHORT...

Posted by supernewbie on August 14, 2009
and what about this portBASE_TYPE? this seems not to be of fixed length, looks like size_t, correct?

RE: length of integral portCHAR portSHORT...

Posted by Richard on August 14, 2009
Look right at the bottom of this page:

http://www.freertos.org/a00017.html#DataTypes

As has already been said, portSHORT is always 16 bits and portLONG is always 32 bits. int is never used. The kernel code uses these definitions in any source file that is compiled for all processors (8, 16 and 32bits), so the kernel code and the common demo code uses them. Your application code does not need to use them unless you want it to be portable across 8, 16 and 32bit architectures too.

portBASE_TYPE is generally used for Boolean values and is set to whatever is the most efficient type for the architecture. Generally this is a char for 8 bitters, short for 16 bitters and long for 32 bitters.

portTickType can be 16 or 32 bits, but it would be very odd to use 16 bits on a 32 bit architecture.

Regards.

RE: length of integral portCHAR portSHORT...

Posted by supernewbie on August 14, 2009
perhaps further silly question, how do you find the size of standard data type for each compiler? did you test all data type by sizeof(standard type) for each compliler? or by look at the docs of the compiler?

Many thanks.

RE: length of integral portCHAR portSHORT...

Posted by dave m on August 14, 2009
I don't know what people generally do, but I might do it either way, depending on what I'm doing and why I want to know. If I'm writing code (so I have my editor, compiler and a test board all ready) I'll do main () { printf( "%d\n", sizeof(int) ); }. (But that's uncommon; if I'm writing code, I usually have a pretty good idea of the datatypes the target supports, and how to specify them to the compiler.) OTOH, if I don't have a dev environment set up, then it's unlikely that I'd need to know in the first place, but if I did, I'd check the compiler docs. It's not worth my time to go idly inquiring into various compilers' default integer sizes on assorted MCUs, though. There's always a way to get the compiler to use the type you want, or the compiler isn't worth wasting time on.

RE: length of integral portCHAR portSHORT...

Posted by supernewbie on August 14, 2009
glad to see the auther of FreeRTOS
wondering that why you choosed to publish your code to be free to open source rather than like uCos which is not free even source open. This might be personal question, there is no abligation to answer.
Secondly, could you please explain what tools you used to test your code, such as static tools Lint, and dynamic tools CUnit, or even more expensive testing tools( but I supposed you not using it to develop the open soure).
Many thanks.


[ 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