[farther OT] Re: Why Is Escaping Data Considered So Magical?

Rami Chowdhury rami.chowdhury at gmail.com
Thu Jul 1 23:17:55 EDT 2010


On Thursday 01 July 2010 16:50:59 Lawrence D'Oliveiro wrote:
> Nevertheless, it it at least self-consistent. To return to my original
> macro:
> 
>     #define Descr(v) &v, sizeof v
> 
> As written, this works whatever the type of v: array, struct, whatever.
> 

Doesn't seem to, sorry. Using Michael Torrie's code example, slightly 
modified...

[rami at tigris ~]$ cat example.c 
#include <stdio.h>

#define Descr(v) &v, sizeof v

int main(int argc, char ** argv)
{
        char *buf = malloc(512 * sizeof(char));
        const int a = 2, b = 3;
        snprintf(Descr(buf), "%d + %d = %d\n", a, b, a + b);
        fprintf(stdout, buf);
        free(buf);
        return 0;
} /*main*/

[rami at tigris ~]$ clang example.c 
example.c:11:18: warning: incompatible pointer types passing 'char **', expected 
'char *' [-pedantic]
        snprintf(Descr(buf), "%d + %d = %d\n", a, b, a + b);
                 ^~~~~~~~~~
example.c:4:18: note: instantiated from:                                                                                               
#define Descr(v) &v, sizeof v
                 ^~~~~~~~~~~~
    <<snip>>
[rami at tigris ~]$ ./a.out 
Segmentation fault


----
Rami Chowdhury
"Passion is inversely proportional to the amount of real information available."
-- Benford's Law of Controversy
+1-408-597-7068 / +44-7875-841-046 / +88-01819-245544



More information about the Python-list mailing list