in reply to defined vs null string
You asked about how it compares with C, so here's a C version:
#include <stdio.h> #include <string.h> char *undef; char *def_empty = ""; char *def = "foo bar"; void check(char *t) { if (t) { if (strlen(t)) { printf("Defined loc=%p, val='%s'\n", t, t); } else { printf("Empty string: loc=%p\n", t); } } else { printf("Undefined (null ptr)\n"); } } int main(int, char **) { check(undef); check(def_empty); check(def); return 0; }
It gives us:
$ ./a.exe Undefined (null ptr) Empty string: loc=0x4020e5 Defined loc=0x4020e6, val='foo bar'
...roboticus
When your only tool is a hammer, all problems look like your thumb.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: defined vs null string
by ikegami (Patriarch) on Aug 30, 2011 at 18:54 UTC |