Re: header files including other files
- From: CBFalconer <cbfalconer@xxxxxxxxx>
- Date: Fri, 07 Sep 2007 09:03:46 -0400
Peter Harrison wrote:
CBFalconer wrote:.... snip ...
Peter Harrison wrote:
I have a C langage project - a small robot. I want to use the
various types defined in stdint.h such as uint8_t, uint16_t and
so on as I expect the code to get ported to other processors.
If you want portability, stay away from those types. They are not
required to be present on any system, but char, short, int, long
are required. You can adjust the type you use by examining the
values of <type>_max and <type>_min available in limits.h.
With that in mind, I had already written my own stdint.h for the
compiler I am using (Microchip C30) and, to take Thad's suggestion
could try and ensure that the environment version got loaded if
present. I figured that, for other compilers, tests in my own
stdint.h for the compiler in use would allow a set of known-width
types. This is partly about saving memory and trying to ensure I
get eight bit quantities an minimum memory footprint. Wouldn't
performing tests on limits.h leave me defining by own types anyway?
You can only create types in C with struct or enums. Anything else
is simply an alias, including those unint8_ts etc. If you want
exactly 8 bits of something, put it in a type that can hold those 8
bits, and mask off anything outside them. You have the standard
guarantees that char, short, int, long can hold at least 8, 16, 16,
32 bits respectively. Your choice as to un/signed versions,
dependant on numeric range and overflow action desired. Remember
that signed objects create undefined or system defined behaviour on
overflow, while unsigned do modulo arithmetic, and are fully
defined at all times (except division by zero).
--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
--
Posted via a free Usenet account from http://www.teranews.com
.
- Follow-Ups:
- Re: header files including other files
- From: Al Balmer
- Re: header files including other files
- References:
- header files including other files
- From: Peter Harrison
- Re: header files including other files
- From: Peter Harrison
- header files including other files
- Prev by Date: Re: LED Display
- Next by Date: Re: how to compile device driver program
- Previous by thread: Re: header files including other files
- Next by thread: Re: header files including other files
- Index(es):
Relevant Pages
|