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

2010-07-03 Thread Lawrence D'Oliveiro
In message , Rami Chowdhury wrote: > 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

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

2010-07-02 Thread Rami Chowdhury
On Friday 02 July 2010 19:20:26 Lawrence D'Oliveiro wrote: > In message , 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 > >

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

2010-07-02 Thread Lawrence D'Oliveiro
In message , 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, wha

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

2010-07-01 Thread Rami Chowdhury
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 Michae

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

2010-07-01 Thread Lawrence D'Oliveiro
In message <4c2ccd9c$0$1643$742ec...@news.sonic.net>, John Nagle wrote: > The approach to arrays in C is just broken, for historical reasons. 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

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

2010-07-01 Thread John Nagle
On 7/1/2010 8:36 AM, Mel wrote: Nobody wrote: On Wed, 30 Jun 2010 23:40:06 -0600, Michael Torrie wrote: Given "char buf[512]", buf's type is char * according to the compiler and every C textbook I know of. References from Kernighan& Ritchie _The C Programming Language_ second edition: No,

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

2010-07-01 Thread Michael Torrie
On 07/01/2010 01:24 AM, Nobody wrote: > No, the type of "buf" is "char [512]", i.e. "array of 512 chars". If you > use "buf" as an rvalue (rather than an lvalue), it will be implicitly > converted to char*. Yes this is true. I misstated. I meant that most text books I've seen say to just use the

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

2010-07-01 Thread Mel
Nobody wrote: > On Wed, 30 Jun 2010 23:40:06 -0600, Michael Torrie wrote: >> Given "char buf[512]", buf's type is char * according to the compiler >> and every C textbook I know of. References from Kernighan & Ritchie _The C Programming Language_ second edition: > No, the type of "buf" is "char

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

2010-07-01 Thread Nobody
On Wed, 30 Jun 2010 23:40:06 -0600, Michael Torrie wrote: > Given "char buf[512]", buf's type is char * according to the compiler > and every C textbook I know of. No, the type of "buf" is "char [512]", i.e. "array of 512 chars". If you use "buf" as an rvalue (rather than an lvalue), it will be i

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

2010-07-01 Thread Jorgen Grahn
On Wed, 2010-06-30, Michael Torrie wrote: > On 06/30/2010 03:00 AM, Jorgen Grahn wrote: >> On Wed, 2010-06-30, Michael Torrie wrote: >>> On 06/29/2010 10:17 PM, Michael Torrie wrote: On 06/29/2010 10:05 PM, Michael Torrie wrote: > #include > > int main(int argc, char ** argv)

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

2010-06-30 Thread Michael Torrie
On 06/30/2010 06:36 PM, Lawrence D'Oliveiro wrote: > In message , > Michael Torrie wrote: > >> Okay, I will. Your code passes a char** when a char* is expected. > > No it doesn’t. You're right; it doesn't. Your code passes char (*)[512]. warning: passing argument 1 of ‘snprintf’ from incompati

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

2010-06-30 Thread Lawrence D'Oliveiro
In message , Michael Torrie wrote: > Okay, I will. Your code passes a char** when a char* is expected. No it doesn’t. > Consider this variation where I use a dynamically allocated buffer > instead of static: And so you misunderstand the difference between a C array and a pointer. -- http://ma

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

2010-06-30 Thread Michael Torrie
On 06/30/2010 03:00 AM, Jorgen Grahn wrote: > On Wed, 2010-06-30, Michael Torrie wrote: >> On 06/29/2010 10:17 PM, Michael Torrie wrote: >>> On 06/29/2010 10:05 PM, Michael Torrie wrote: #include int main(int argc, char ** argv) { char *buf = malloc(512 * sizeof(char));

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

2010-06-30 Thread Jorgen Grahn
On Wed, 2010-06-30, Michael Torrie wrote: > On 06/29/2010 10:17 PM, Michael Torrie wrote: >> On 06/29/2010 10:05 PM, Michael Torrie wrote: >>> #include >>> >>> int main(int argc, char ** argv) >>> { >>> char *buf = malloc(512 * sizeof(char)); >>> const int a = 2, b = 3; >>> snprintf(&b

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

2010-06-29 Thread Michael Torrie
On 06/29/2010 10:17 PM, Michael Torrie wrote: > On 06/29/2010 10:05 PM, Michael Torrie wrote: >> #include >> >> int main(int argc, char ** argv) >> { >> char *buf = malloc(512 * sizeof(char)); >> const int a = 2, b = 3; >> snprintf(&buf, sizeof buf, "%d + %d = %d\n", a, b, a + b); >

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

2010-06-29 Thread Michael Torrie
On 06/29/2010 10:05 PM, Michael Torrie wrote: > #include > > int main(int argc, char ** argv) > { > char *buf = malloc(512 * sizeof(char)); > const int a = 2, b = 3; > snprintf(&buf, sizeof buf, "%d + %d = %d\n", a, b, a + b); ^^ Make that 512*size

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

2010-06-29 Thread Michael Torrie
On 06/29/2010 06:25 PM, Lawrence D'Oliveiro wrote: > I have yet to find an architecture or C compiler where it DOESN’T work. > > Feel free to try and prove me wrong. Okay, I will. Your code passes a char** when a char* is expected. Every compiler I know of will give you a *warning*. Mistaking c

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

2010-06-29 Thread Lawrence D'Oliveiro
In message , Kushal Kumaran wrote: > On Tue, Jun 29, 2010 at 5:56 AM, Lawrence D'Oliveiro > wrote: > >> Why does this work, then: >> >> l...@theon:hack> cat test.c >> #include >> >> int main(int argc, char ** argv) >> { >>char buf[512]; >>const int a = 2, b = 3; >>snprintf(&buf, si

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

2010-06-28 Thread Kushal Kumaran
On Tue, Jun 29, 2010 at 5:56 AM, Lawrence D'Oliveiro wrote: > In message , Kushal > Kumaran wrote: > >> On Sun, Jun 27, 2010 at 5:16 PM, Lawrence D'Oliveiro >> wrote: >> >>>In message , Kushal >>> Kumaran wrote: >>> On Sun, Jun 27, 2010 at 9:47 AM, Lawrence D'Oliveiro wrote: >

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

2010-06-28 Thread Lawrence D'Oliveiro
In message , Kushal Kumaran wrote: > On Sun, Jun 27, 2010 at 5:16 PM, Lawrence D'Oliveiro > wrote: > >>In message , Kushal >> Kumaran wrote: >> >>> On Sun, Jun 27, 2010 at 9:47 AM, Lawrence D'Oliveiro >>> wrote: >>> A long while ago I came up with this macro: #define Descr(v) &v,

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

2010-06-27 Thread Kushal Kumaran
On Sun, Jun 27, 2010 at 5:16 PM, Lawrence D'Oliveiro wrote: > In message , Kushal > Kumaran wrote: > >> On Sun, Jun 27, 2010 at 9:47 AM, Lawrence D'Oliveiro >> wrote: >> >>> In message , Roy Smith wrote: >>> I recently fixed a bug in some production code.  The programmer was careful to