Re: header files including other files



Peter Harrison wrote:
CBFalconer wrote:
Peter Harrison wrote:

.... snip ...

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

.



Relevant Pages

  • Re: header files including other files
    ... compiler I am using and, ... get eight bit quantities an minimum memory footprint. ... performing tests on limits.h leave me defining by own types anyway? ... guarantees that char, short, int, long can hold at least 8, 16, 16, ...
    (comp.arch.embedded)
  • Re: header files including other files
    ... Really I guess I am asking advice about source code organisation. ... With that in mind, I had already written my own stdint.h for the compiler I am using and, to take Thad's suggestion could try and ensure that the environment version got loaded if present. ... 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? ...
    (comp.arch.embedded)
  • Re: It Pays to Enrich Your C Skills
    ... Check if you can score a perfect 10 (without using a compiler). ... int main{ ... struct bitfield { ... out if it is a negative integer constant or a constant expression ...
    (comp.lang.c.moderated)
  • OT: Re: Perl Peeves
    ... I see the result of a test being used as an int. ... the compiler just assumed you knew what you were doing ... introduced to the language later, so void * was unheard of in most code. ... This didn't mean bool was special, declaring it just signaled to the ...
    (comp.lang.perl.misc)
  • Re: OT: Re: Perl Peeves
    ... when I see the result of a test being used as an int. ... compiler just assumed you knew what you were doing and would ... This didn't mean bool was special, declaring it just signaled to the ... What "normalization of bool results is built into the compiler"? ...
    (comp.lang.perl.misc)