EmbeddedRelated.com
Forums
Memfault Beyond the Launch

Making a function safe for use in an ISR

Started by joshc January 24, 2007
In article <m3ireledq6.fsf@Claudio.Messina>, Mark L Pappin <mlp@acm.org> 
writes
>Chris Hills <chris@phaedsys.org> writes: > >> Paul Keinanen <keinanen@sci.fi> writes >>> "Gary Pace" <xxx@yyy> wrote: >>>> - i is signed, int may be 8,16,32 (maybe 64?) bits in size >>> If this is supposed to be standard C, then int can not be 8 bits. > >> No, this is for an embedded MCU so it can be 8 bits. > >Not if you want to call the language C. >You can call it "C-like" if you want,
You are being a pedant and pointless.
> but for the last 17 years there >has been an international standard defining the language called C
I know I have been on that panel for about a decade.
>and >one of its most fundamental features is that the type 'int' can hold >all values between 32767 and -32767 inclusive.
This is not correct. Type in should be at least 16 bits. Ints can legally be any size above 16 bits. There are systems with 64 bit ints. Also an int can be signed or unsigned. An unsigned int does not hold negative values... Of course both signed and unsigned char are integer types though a char does not have to be 8 bits. Hence the communications industry having the type "octet" which we have suggested as a standard type on more than one occasion.
>A language with a type >'int' that can not hold at least this range can not be called C.
As I said you are a pedant and pointless. The difference between theory and practice.... There are many dialects of C Most break the rules somewhere. By your definition there are only , I think, 6 C compilers world wide but they only could for a minute fraction of the "c" programming in the world. The vast majority do not fully implement ISO 9899:1999 but rather something between C95 and C99 *with extensions* There are some compilers that are as compliant as most of the other c compilers out there that for reasons of hardware architecture and efficiency my have 8 bit ints. It is not common but I would not stop them being called C compilers for just that reason alone.
>The C standard _does_ allow for various extensions, and makes the >distinction between "freestanding" and "hosted" implementations (most >embedded platforms will be the former, which for instance doesn't need >to provide all or even any of the standard library) but reducing the >range of _the_ basic type in this way is just not on. >mlp
As I said all "c" compilers have extensions and restrictions on ISO9899:1999. I think only 6 fully implement the standard, all the common ones don't, ALL of the C compilers have extensions. C is like English, rarely ever used in it's pure form. -- \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ \/\/\/\/\ Chris Hills Staffs England /\/\/\/\/ /\/\/ chris@phaedsys.org www.phaedsys.org \/\/\ \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
Chris Hills wrote:
> Mark L Pappin <mlp@acm.org> writes >> Chris Hills <chris@phaedsys.org> writes: >>> Paul Keinanen <keinanen@sci.fi> writes >>>
... snip ...
>>> >>>> If this is supposed to be standard C, then int can not be 8 bits. >>> >>> No, this is for an embedded MCU so it can be 8 bits. >> >> Not if you want to call the language C. >> You can call it "C-like" if you want, > > You are being a pedant and pointless. > >> but for the last 17 years there >> has been an international standard defining the language called C > > I know I have been on that panel for about a decade.
Then you should know better. I suspect you are largely ignored.
> >> and one of its most fundamental features is that the type 'int' >> can hold all values between 32767 and -32767 inclusive. > > This is not correct. Type in should be at least 16 bits. Ints can > legally be any size above 16 bits. There are systems with 64 bit ints.
All of which can hold values between 32767 and -32767 as he said.
> > Also an int can be signed or unsigned. An unsigned int does not hold > negative values... > > Of course both signed and unsigned char are integer types though a > char does not have to be 8 bits. Hence the communications industry > having the type "octet" which we have suggested as a standard type > on more than one occasion.
unsigned ints are not ints. They are a different type and follow different rules, such as the use of modulo arithmetic. Which doesn't affect the statement about ints.
> >> A language with a type >> 'int' that can not hold at least this range can not be called C. > > As I said you are a pedant and pointless. The difference between > theory and practice.... > > There are many dialects of C Most break the rules somewhere. By > your definition there are only , I think, 6 C compilers world > wide but they only could for a minute fraction of the "c" > programming in the world. The vast majority do not fully implement > ISO 9899:1999 but rather something between C95 and C99 *with > extensions*
Then it isn't a C compiler, by definition. It may still be useful. The point of a standard is to allow confidence that source code will work on any system that is standards compliant. Use of extensions should be limited to clearly identified modules. -- <http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt> "A man who is right every time is not likely to do very much." -- Francis Crick, co-discover of DNA "There is nothing more amazing than stupidity in action." -- Thomas Matthews
In article <45C33455.7887F4C3@yahoo.com>, CBFalconer 
<cbfalconer@yahoo.com> writes
>Chris Hills wrote: >> There are many dialects of C Most break the rules somewhere. By >> your definition there are only , I think, 6 C compilers world >> wide but they only could for a minute fraction of the "c" >> programming in the world. The vast majority do not fully implement >> ISO 9899:1999 but rather something between C95 and C99 *with >> extensions* > >Then it isn't a C compiler, by definition.
This sort of stupidity is prevalent on comp.lang.c but thankfully not on the standards panels. I am surprised to see in an embedded NG. By your definition there are only 6 C compilers and non of them in the embedded area. -- \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ \/\/\/\/\ Chris Hills Staffs England /\/\/\/\/ /\/\/ chris@phaedsys.org www.phaedsys.org \/\/\ \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Memfault Beyond the Launch