EETimes

Embedded Systems October 2000 Vol13_11

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

Contents of this Issue

Navigation

Page 78 of 181

• PROGRAMMING POINTERS Changing the type of sU-ing li terals to "array of const char" introduces a problem for existing C++ programs containing code such as: void g(char *); g("abc"); He re , 9 is not overloaded. The re's one function g, and it accepts an argument of type "pointer to (non- const) char." Calling g("abc") is valid C, and used to be valid C++. However, now that C++ regards "abc" as an "array of const char," thi s call requires a seemingly invalid pointer conve rsio n . For compa tibili ty with existin g code, C++ will sti ll convert a stt-ing lit- eral to a "poin ter to (non-const) char" a a special case. Even though C++ will not convert any old "array of const char" to "pointer to char," it will do so o nly for sU-ing li terals. This is so that code such as the pl-ior call to g("abc") will continue to compile. However, the conve l-sion from string lite ral to "poin ter to char" is deprecated, which means that it may disappear from a future C++ standard. Dan SailS is the IJTesident of SailS & Associates, a C/C++ training and consult- ing company. He is also a consulting editor for the C/ C++ UsersJoumal. He servedf01- many years as secretary of the c++ standm'ds committee. With 77w'fTWS Plum, he wrote ++ Programming Guidelines. You can wril.e to him at dsallS@wittenb(1rg. edu. References 1. Saks, Dan, "Numeric Literals," Embedded Systems Programming, September 2000, p. 113. 2. Stroustrup, Bjarne. The Design and Evolution of C++. Reading, MA: Addison-Wesley, 1994. 3.Saks, Dan, "Is an Array Really Just a Pointer?" Embedded Systems Programming, June 2000, p. 15. 4. Saks, Dan, "Using const and volatile in Parameter Types," Embedded Systems Programming, September 1999, p. 77.

Articles in this issue

Archives of this issue

view archives of EETimes - Embedded Systems October 2000 Vol13_11