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

Rami Chowdhury rami.chowdhury at gmail.com
Fri Jul 2 23:07:24 EDT 2010


On Friday 02 July 2010 19:20:26 Lawrence D'Oliveiro wrote:
> 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

I'm sorry, perhaps you've misunderstood what I was refuting. You posted:
> >> macro:
> >>     #define Descr(v) &v, sizeof v
> >> 
> >> As written, this works whatever the type of v: array, struct, whatever.

With my code example I found that, as others have pointed out, unfortunately it 
doesn't work if v is a pointer to a heap-allocated area. 

----
Rami Chowdhury
"A man with a watch knows what time it is. A man with two watches is never
sure". -- Segal's Law
+1-408-597-7068 / +44-7875-841-046 / +88-01819-245544



More information about the Python-list mailing list