* HACKING (Programming tips): added a tip concerning the NULL

pointer in varargs function calls.
This commit is contained in:
Roland Illig 2004-09-24 14:19:21 +00:00
parent ad1e412fa1
commit df14f4860c
2 changed files with 15 additions and 1 deletions

View File

@ -1,3 +1,8 @@
2004-09-24 Roland Illig <roland.illig@gmx.de>
* HACKING (Programming tips): added a tip concerning the NULL
pointer in varargs function calls.
2004-09-22 Roland Illig <roland.illig@gmx.de> 2004-09-22 Roland Illig <roland.illig@gmx.de>
* HACKING: added advice for using g_strdup for a modifiable * HACKING: added advice for using g_strdup for a modifiable

11
HACKING
View File

@ -331,7 +331,7 @@ g_free: g_free handles NULL argument too, no need for the comparison.
Right way: Right way:
g_free (old_dir); g_free (old_dir);
g_strdup: If you use g_strdup to create a local copy of a string, use g_strdup: When you use g_strdup to create a local copy of a string, use
the following pattern to keep the reference. the following pattern to keep the reference.
char * const pathref = g_strdup(argument); char * const pathref = g_strdup(argument);
@ -345,6 +345,15 @@ g_strlcpy: Whenever you use this function, be sure to add "glibcompat.h"
to the included headers. This is because in glib-1.2 there is to the included headers. This is because in glib-1.2 there is
no such function. no such function.
NULL: When you pass NULL as an argument of a varargs function, cast the
NULL to the appropriate data type. If a system #defines NULL to
be 0 (at least NetBSD and OpenBSD do), and the sizes of int and
a pointer are different, the argument will be passed as int 0,
not as a pointer.
example:
char *path = g_strconcat("dir", "/", "file", (char *) NULL);
size_t: This data type is suitable for expressing sizes of memory or the size_t: This data type is suitable for expressing sizes of memory or the
length of strings. This type is unsigned, so you need not check length of strings. This type is unsigned, so you need not check
if the value is >= 0. if the value is >= 0.