From 7e0f021a9aec35fd8e6725e87e3313b101d26f5e Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sun, 27 Jan 2008 11:37:44 +0100 Subject: Initial import (2.0.2-6) --- reference/C/SYNTAX/idioms.html | 136 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 reference/C/SYNTAX/idioms.html (limited to 'reference/C/SYNTAX/idioms.html') diff --git a/reference/C/SYNTAX/idioms.html b/reference/C/SYNTAX/idioms.html new file mode 100644 index 0000000..62247d3 --- /dev/null +++ b/reference/C/SYNTAX/idioms.html @@ -0,0 +1,136 @@ +Idioms + + + + +
+
+

Idioms

+
+
+

+ +Here are some C idioms that may be usefull. + +


+Place \0 at the location pointed to by ptr +then increment ptr +

+

+ + +
+
+
+   *ptr++ = '\0';   
+
+
+
+ +


+Increment ptr then +place \0 at the location pointed to by ptr +

+

+ + +
+
+
+   *++ptr = '\0';   
+
+
+
+ +


+This program will print its self! I guess its not of any real +use, but I think its clever. +

+

+ + +
+
+
+  main(a) {a="main(a) {a=%c%s%c;printf(a,34,a,34);}";printf(a,34,a,34);}  
+
+
+
+ +


+This is something I saw out on the web. It swaps the value of two +variables without +using a third variable as a temporary store. +

+

+ + +
+
+
+   one ^= two;   
+   two ^= one;
+   one ^= two;
+
+
+
+ + +


+ +Have you ever had a SEGV from printf +because you passed a NULL pointer to a %s flag???. This idiom will put +a stop to all that nonsence. +

+

+ + +
+
+
+   printf("%s\n", Str ? Str : "Null");   
+
+
+
+ + + +


+

+o +Program swapping the contents of two variables. +

+ +


+

See Also:

+ +o +Common Coding Errors.

+ + +

+ +


+

+

+ + + + +
+ Top + + Master Index + + Keywords + + Functions +
+
+

+


+
Martin Leslie +

+ + -- cgit v1.2.3-54-g00ecf