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...

[r...@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*/

[r...@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>>
[r...@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
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to