[farther OT] Re: Why Is Escaping Data Considered So Magical?
Lawrence D'Oliveiro
ldo at geek-central.gen.new_zealand
Fri Jul 2 22:20:26 EDT 2010
In message <mailman.136.1278040489.1673.python-list at python.org>, Rami
Chowdhury wrote:
> 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...
>
> char *buf = malloc(512 * sizeof(char));
Again, you misunderstand the difference between a C array and a pointer.
Study the following example, which does work, and you might grasp the point:
ldo at theon:hack> cat test.c
#include <stdio.h>
int main(int argc, char ** argv)
{
char buf[512];
const int a = 2, b = 3;
snprintf(&buf, sizeof buf, "%d + %d = %d\n", a, b, a + b);
fprintf(stdout, buf);
return
0;
} /*main*/
ldo at theon:hack> ./test
2 + 3 = 5
More information about the Python-list
mailing list