Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C Programming
Is C99 the final C?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Paul Hsieh, post: 1690678"] So, rather than implementing a whole new mechanism that takes the language in another direction, why not try to implement templates using the existing facilities and see where we are lacking? The most obvious thing to use is macros -- in fact, I actually use macros for templates all the time. But one has a difficult time publishing a library of templates (you know something like a ... STANDARD TEMPLATE LIBRARY) using such an idea because of the following: - The preprocessor does not have its own namespace for its own symbols, so even something as simple as declaring temporaries and using them with other variables passed as parameters is walking a tight rope since the author cannot guarantee that its in a different name space, and therefore might collide unintentionally. For example: #define swap(type,v1,v2) do { \ type tmp; \ tmp = v1; \ v1 = v2; \ v2 = tmp; \ } while (0) actually doesn't work for something like swap(int,tmp,tmp1); So using something like $tmp instead would be better -- the idea being that "$" would be a valid symbol prefix only in the preprocessor context and be the syntax error you would expect it to be in ordinary C code. - There is no type checking of parameters that can be performed at compile time. Implementing compile time mechanisms as simple as: assertTypeEqual(a, b, ...) - Issues a compile time error if all the parameters are not exactly equal in type. assertTypeOneOf(a, b, ...) - Issues error if a is not the same as at least one of the types of the rest of the parameters. assertTypeCoercable(a, b, ...) - Issues error any pair of the set of parameters are not coercable with each other. would solve this problem. - Once cannot perform computations or useful control flow at preprocessor time. Compare with the Microsoft Assembler's preprocessor for example. Such features would #forc $c in "ABCDEF..." putchar($c) #endforc would result in putchar('A'); putchar ('B'); ... etc. #for $c in 0,1,2,3,4,5 # define $d #eval($c * 2) printf ("%2d", $c); #endfor would result in printf("%2d", 0); print ("%2d", 2); ... etc. #range(0,5) would expand as 0,1,2,3,4 and so on. Such ideas could also take away a lot of the ideas like "lambda expansion" in languages like Lisp/Scheme. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
Is C99 the final C?
Top