Using Compiler Extensions

Every C++ compiler has a few special features. These features can be helpful, as long as you keep in mind that they are not portable. For example, GCC's typeof operator has also (more or less independently) been implemented in UnderC. (It is on Bjarne Stroustrup's list of things he would like to see in the next standard C++ revision, so its future is promising.) The basic idea is that you can use it in declarations, where type usually has the following form:

;> int i;
;> typeof(i) k,l,m;
					

This might seem like a roundabout way of declaring integer variables, but some entertaining things become possible. Control-statement macros become even more expressive with the use of typeof. For example, it is common to use an iterator ...

Get C++ By Example: UnderC Learning Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.