Re: [DNG] "Common knowledge?"-question

2016-01-26 Thread Rainer Weikusat
Steve Litt writes: > Rainer Weikusat wrote: > >> Can the effect of the following C function >> >> static void print_start(char const *name, char const *what) >> { [...] >> } >> >> be considered obvious or should it rather get an

Re: [DNG] "Common knowledge?"-question

2016-01-25 Thread Dr. Nikolaus Klepp
Am Montag, 25. Januar 2016 schrieb Rainer Weikusat: > "Dr. Nikolaus Klepp" writes: > > [...] > > > What about making the source smaller and not the executable? > > > > static void print_start(char const *name, char const *what) { > > if (name[0])

Re: [DNG] "Common knowledge?"-question

2016-01-25 Thread Didier Kryn
Le 24/01/2016 19:14, KatolaZ a écrit : Soo, the above is nearly the same as > > char buf[total]; > p = buf; > >Why then use alloca()? > Maybe because char buf[total]; works only in ANSI C11. I still don't see the need for an internal buffer to print out a formatted string, to be

Re: [DNG] "Common knowledge?"-question

2016-01-25 Thread KatolaZ
On Mon, Jan 25, 2016 at 09:27:15AM +0100, Didier Kryn wrote: [cut] > > The following works in plain old C: > > #include > #include > static void print_start(char const *name, char const *what) > { > unsigned name_len, what_len, total; > > name_len = strlen(name); >

Re: [DNG] "Common knowledge?"-question

2016-01-25 Thread Didier Kryn
Le 25/01/2016 11:34, KatolaZ a écrit : I would say that having embedded subprograms in a function is not the best thing one can do in C Every block is a subprogram. The block in a do loop, the conditional block in an if or while statement. The subprogram blocks are everywhere in C;

Re: [DNG] "Common knowledge?"-question

2016-01-25 Thread Dr. Nikolaus Klepp
Am Montag, 25. Januar 2016 schrieb KatolaZ: > On Mon, Jan 25, 2016 at 09:27:15AM +0100, Didier Kryn wrote: > > [cut] > > > > > The following works in plain old C: > > > > #include > > #include > > static void print_start(char const *name, char const *what) > > { > > unsigned

Re: [DNG] "Common knowledge?"-question

2016-01-25 Thread KatolaZ
On Mon, Jan 25, 2016 at 12:18:09PM +0100, Dr. Nikolaus Klepp wrote: [cut] > > What about making the source smaller and not the executable? > > static void print_start(char const *name, char const *what) { > if (name[0]) fprintf("%c%s",name[0]&~0x20, name+1); > fprintf(stderr, " %s:

Re: [DNG] "Common knowledge?"-question

2016-01-25 Thread Rainer Weikusat
Didier Kryn writes: > Le 24/01/2016 19:14, KatolaZ a écrit : >>> Soo, the above is nearly the same as >>> > >>> > char buf[total]; >>> > p = buf; >>> > >>> >Why then use alloca()? >>> > >> Maybe because >> char buf[total]; >> >> works only in ANSI C11. I still don't see

Re: [DNG] "Common knowledge?"-question

2016-01-25 Thread Rainer Weikusat
"Dr. Nikolaus Klepp" writes: [...] > What about making the source smaller and not the executable? > > static void print_start(char const *name, char const *what) { > if (name[0]) fprintf("%c%s",name[0]&~0x20, name+1); > fprintf(stderr, " %s: ",what); > } Are you

Re: [DNG] "Common knowledge?"-question

2016-01-24 Thread Rainer Weikusat
Peter Olson writes: >> On January 23, 2016 at 1:36 PM Rainer Weikusat >> wrote: >> >> Peter Olson writes: >> 5>> On January 22, 2016 at 4:34 PM Rainer Weikusat >> wrote: >> >> [...] >> >> >>

Re: [DNG] "Common knowledge?"-question

2016-01-24 Thread Rainer Weikusat
Didier Kryn writes: > Le 23/01/2016 19:28, Rainer Weikusat a écrit : >> Didier Kryn writes: >>> Le 23/01/2016 12:16, Didier Kryn a écrit : I'm curious of the reason why you specify static void print_start(char const *name, char const *what) [...]

Re: [DNG] "Common knowledge?"-question

2016-01-24 Thread Rainer Weikusat
k...@aspodata.se writes: > Katola2: > ... >> void another_print_start(char *name, char *what){ >> >> char c[3] = " :"; >> >> c[2] = name[0] & ~0x20; >> >> write(2, c+2, 1); >> write(2, name+1, strlen(name) -1); >> write(2, c, 2); >> write(2, what, strlen(what)); >> >> } > > Why not just

Re: [DNG] "Common knowledge?"-question

2016-01-24 Thread karl
Reiner Weikusat: > Peter Olson writes: > > >> On January 23, 2016 at 1:36 PM Rainer Weikusat > >> wrote: > >> > >> Peter Olson writes: > >> 5>> On January 22, 2016 at 4:34 PM Rainer Weikusat > >>

Re: [DNG] "Common knowledge?"-question

2016-01-24 Thread karl
Rainer Weikusat: > k...@aspodata.se writes: > > Katola2: > > ... > >> void another_print_start(char *name, char *what){ > >> > >> char c[3] = " :"; > >> > >> c[2] = name[0] & ~0x20; > >> > >> write(2, c+2, 1); > >> write(2, name+1, strlen(name) -1); > >> write(2, c, 2); > >> write(2,

Re: [DNG] "Common knowledge?"-question

2016-01-24 Thread KatolaZ
On Sun, Jan 24, 2016 at 05:25:47PM +0100, k...@aspodata.se wrote: [cut] > ... > > In this respect, there's no difference between alloca and static stack > > allocations. > ... > > Soo, the above is nearly the same as > > char buf[total]; > p = buf; > > Why then use alloca()? > Maybe

Re: [DNG] "Common knowledge?"-question

2016-01-24 Thread Rainer Weikusat
"Dr. Nikolaus Klepp" writes: > Am Freitag, 22. Januar 2016 schrieb Rainer Weikusat: [...] >> name_len = strlen(name); >> what_len = strlen(what); >> total = name_len + what_len + 3; >> >> p = buf = alloca(total); >> memcpy(p, name, name_len); >> p

Re: [DNG] "Common knowledge?"-question

2016-01-24 Thread Rainer Weikusat
k...@aspodata.se writes: > Reiner Weikusat: >> Peter Olson writes: >> >> >> On January 23, 2016 at 1:36 PM Rainer Weikusat >> >> wrote: >> >> >> >> Peter Olson writes: >> >> 5>> On January 22, 2016 at 4:34 PM Rainer Weikusat >>

Re: [DNG] "Common knowledge?"-question

2016-01-24 Thread Rainer Weikusat
k...@aspodata.se writes: > Reiner Weikusat: >> Peter Olson writes: >> >> >> On January 23, 2016 at 1:36 PM Rainer Weikusat >> >> wrote: >> >> >> >> Peter Olson writes: >> >> 5>> On January 22, 2016 at 4:34 PM Rainer Weikusat >>

Re: [DNG] "Common knowledge?"-question

2016-01-24 Thread Rainer Weikusat
k...@aspodata.se writes: > Rainer Weikusat: >> k...@aspodata.se writes: >> > Katola2: >> > ... >> >> void another_print_start(char *name, char *what){ >> >> >> >> char c[3] = " :"; >> >> >> >> c[2] = name[0] & ~0x20; >> >> >> >> write(2, c+2, 1); >> >> write(2, name+1, strlen(name) -1); >>

Re: [DNG] "Common knowledge?"-question

2016-01-23 Thread KatolaZ
On Sat, Jan 23, 2016 at 02:10:46AM -0500, Peter Olson wrote: [cut] > > I'm unhappy for two reasons: > > the failure mode of alloca is SIGSEGV or some other malfunction and there is > no way to test for it > > the *buf &= ~0x20; breaks for UTF8 strings. > > Nevermind that the function

Re: [DNG] "Common knowledge?"-question

2016-01-23 Thread Didier Kryn
Le 22/01/2016 22:34, Rainer Weikusat a écrit : Can the effect of the following C function static void print_start(char const *name, char const *what) { char *buf, *p; unsigned name_len, what_len, total; name_len = strlen(name); what_len = strlen(what); total = name_len

Re: [DNG] "Common knowledge?"-question

2016-01-23 Thread Didier Kryn
Le 23/01/2016 14:48, Hendrik Boom a écrit : I've always said the C syntax for declarators was confusing. Even those who understand it read it wrong! (Yes, In understand the logic behind it. It is still confusing.) I fully agree: it's confusing. Actually, in a single statement one can

Re: [DNG] "Common knowledge?"-question

2016-01-23 Thread Steve Litt
On Fri, 22 Jan 2016 21:34:28 + Rainer Weikusat wrote: > Can the effect of the following C function > > static void print_start(char const *name, char const *what) > { > char *buf, *p; > unsigned name_len, what_len, total; > > name_len =

Re: [DNG] "Common knowledge?"-question

2016-01-23 Thread Hendrik Boom
On Sat, Jan 23, 2016 at 11:45:30AM -0500, Steve Litt wrote: > On Fri, 22 Jan 2016 21:34:28 + > Rainer Weikusat wrote: > > > Can the effect of the following C function > > > > static void print_start(char const *name, char const *what) > > { > > char *buf,

Re: [DNG] "Common knowledge?"-question

2016-01-23 Thread Rainer Weikusat
Didier Kryn writes: > Le 23/01/2016 12:16, Didier Kryn a écrit : >> >> I'm curious of the reason why you specify >>static void print_start(char const *name, char const *what) >> >> This means the pointers to the arrays of characters are constant >> (not the

Re: [DNG] "Common knowledge?"-question

2016-01-23 Thread KatolaZ
On Sat, Jan 23, 2016 at 06:59:10PM +0100, Didier Kryn wrote: [cut] > > The syntax used by Rainer is usefull when declaring in the same > statement constant and non-constant characters, which I, personnaly, > try to avoid because it is confusing. Confusing statements simply > boost the

Re: [DNG] "Common knowledge?"-question

2016-01-23 Thread KatolaZ
On Sat, Jan 23, 2016 at 06:36:46PM +, Rainer Weikusat wrote: > Peter Olson writes: > 5>> On January 22, 2016 at 4:34 PM Rainer Weikusat > wrote: > > [...] > > >> p = buf = alloca(total); > > [...] > > > the failure mode of alloca is

Re: [DNG] "Common knowledge?"-question

2016-01-23 Thread Hendrik Boom
On Sat, Jan 23, 2016 at 04:45:05PM +0100, Didier Kryn wrote: > Le 23/01/2016 12:16, Didier Kryn a écrit : > > > >I'm curious of the reason why you specify > > static void print_start(char const *name, char const *what) > > > >This means the pointers to the arrays of characters are >

Re: [DNG] "Common knowledge?"-question

2016-01-23 Thread Didier Kryn
Le 23/01/2016 12:16, Didier Kryn a écrit : I'm curious of the reason why you specify static void print_start(char const *name, char const *what) This means the pointers to the arrays of characters are constant (not the characters). The effect of this cannot be to protect the

Re: [DNG] "Common knowledge?"-question

2016-01-23 Thread karl
Katola2: ... > void another_print_start(char *name, char *what){ > > char c[3] = " :"; > > c[2] = name[0] & ~0x20; > > write(2, c+2, 1); > write(2, name+1, strlen(name) -1); > write(2, c, 2); > write(2, what, strlen(what)); > > } Why not just use writev(2) and write it one system call ?

Re: [DNG] "Common knowledge?"-question

2016-01-23 Thread Rainer Weikusat
Peter Olson writes: 5>> On January 22, 2016 at 4:34 PM Rainer Weikusat wrote: [...] >> p = buf = alloca(total); [...] > the failure mode of alloca is SIGSEGV or some other malfunction and > there is no way to test for it It's supposed

Re: [DNG] "Common knowledge?"-question

2016-01-23 Thread Peter Olson
> On January 23, 2016 at 1:36 PM Rainer Weikusat > wrote: > > Peter Olson writes: > 5>> On January 22, 2016 at 4:34 PM Rainer Weikusat > wrote: > > [...] > > >> p = buf = alloca(total); > > [...] > > >

Re: [DNG] "Common knowledge?"-question

2016-01-23 Thread Didier Kryn
Le 23/01/2016 19:28, Rainer Weikusat a écrit : Didier Kryn writes: Le 23/01/2016 12:16, Didier Kryn a écrit : I'm curious of the reason why you specify static void print_start(char const *name, char const *what) This means the pointers to the arrays of characters

[DNG] "Common knowledge?"-question

2016-01-22 Thread Rainer Weikusat
Can the effect of the following C function static void print_start(char const *name, char const *what) { char *buf, *p; unsigned name_len, what_len, total; name_len = strlen(name); what_len = strlen(what); total = name_len + what_len + 3; p = buf = alloca(total);

Re: [DNG] "Common knowledge?"-question

2016-01-22 Thread KatolaZ
On Fri, Jan 22, 2016 at 09:34:28PM +, Rainer Weikusat wrote: > Can the effect of the following C function > > static void print_start(char const *name, char const *what) > { [cut] > be considered obvious or should it rather get an explanation? > katolaZ said: Well, it will depend on

Re: [DNG] "Common knowledge?"-question

2016-01-22 Thread Dr. Nikolaus Klepp
Am Freitag, 22. Januar 2016 schrieb Rainer Weikusat: > Can the effect of the following C function > > static void print_start(char const *name, char const *what) > { > char *buf, *p; > unsigned name_len, what_len, total; > > name_len = strlen(name); > what_len = strlen(what); >

Re: [DNG] "Common knowledge?"-question

2016-01-22 Thread Peter Olson
> On January 22, 2016 at 4:34 PM Rainer Weikusat > wrote: > > Can the effect of the following C function > > static void print_start(char const *name, char const *what) > { > char *buf, *p; > unsigned name_len, what_len, total; > > name_len =

Re: [DNG] "Common knowledge?"-question

2016-01-22 Thread Gregory Nowak
On Fri, Jan 22, 2016 at 09:34:28PM +, Rainer Weikusat wrote: > Can the effect of the following C function > > static void print_start(char const *name, char const *what) > { > char *buf, *p; > unsigned name_len, what_len, total; > > name_len = strlen(name); > what_len =