EETimes

Embedded Systems September 2000 Vol13_10

Issue link: http://dc.ee.ubm-us.com/i/71837

Contents of this Issue

Navigation

Page 114 of 229

Dan Saks Numeric Literals The C language provides several different kinds of constants: integer constants such as 10 and Ox1 C, floating constants such as 1.0 and 6.022e+23, and character constants such as 'a 1 1 \ x1 0 1 and • C also provides string literals such as "ouch! " and "\n". C++ pro- vides the same kinds of constants and literals, except the C++ standard just calls al l of them literals in tead. I do, too. Every literal in C and C++ has a type. For example, 1 0 is obviously an integer. But is it an i n t (which is signed by default) an unsigned i n t , or a s h o r t or L on g variation thereof? Do you even care? If you' re a C programme r, you might not care. Part of me hopes you 'd care, but I'm not absolute ly sure you need to . Many C program- me rs apparently get by quite well without kn owing the exact types of constants. If you ' re a C++ programme r, you really sh ould care. C++ upports function name over loading, and th e exact typ e of a li teral just might de termine which function is the best ma tch fo r a particu la r call. For example, give n: int H i nt); unsigned i nt f(unsigned i nt); Long int f(Long int); which of these functions does f(1Q) call? The answer is: i nt f

Articles in this issue

Archives of this issue

view archives of EETimes - Embedded Systems September 2000 Vol13_10