From: "Tim Nicholson" Newsgroups: comp.os.msdos.djgpp Subject: Re: Please add strrev proposal Date: Sat, 29 Sep 2001 21:15:04 +0100 Organization: Skyforce avionics Limited Lines: 201 Message-ID: <9p5a8n$oq0$1@uranium.btinternet.com> References: <3BB50884 DOT 347A4384 AT yahoo DOT com> <3BB55487 DOT CC4407ED AT worldnet DOT att DOT net> <9p4jri$q73$1 AT uranium DOT btinternet DOT com> <02pbrto99332j0s1mnkvhl4sts5828rqiu AT 4ax DOT com> NNTP-Posting-Host: host213-1-82-200.btinternet.com X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com I can't claim to fully understand what your last message was trying to tell me, but, like it or not, the statement: printf("%s %s",str,strrev(str)); will print the reverse string twice on every version of C you care to try it on. BTW I did not intend to imply that printf() would call anything, I just attempted to point out that it would have to if it was to behave the way you seem to think it should! I recommend that you try coding it for real rather than quote a load of out of context snippets! (No offence) Tim wrote in message news:02pbrto99332j0s1mnkvhl4sts5828rqiu AT 4ax DOT com... > At the risk of being redundant: > > > If your compiler actually outputs both strings as reversed, > THEN I am very scared your compiler is quite BROKEN. > > printf("format specifier1, format_specififer2", var1, func1); > > does: > display __current__ value of var1 FIRST using format_specifier1, > __THEN__ > display __output__ of funct1 using format_specifier2, > > { there just is not any other way to say this more clearly } > > [[snippity-snip]] > > { Print, } > Left to right, in the order AND STATE ENCOUNTERED! > { values, values_to_functions } > > ....however... __AFTER__ the call to printf(), __THEN__ > 'str' will contain the result of the function call; > but > __NEVER__ > from __WITHIN__ the printf as > you implied. Your post is VERY MISLEADING. > > > { and that will be all I will offer to this thread } > > On Sat, 29 Sep 2001 14:52:36 +0100, "Tim Nicholson" > wrote: > > >If you think about it, it could not work any other way. The string only > >exists in one state or the other. (i.e. forward state or reverse state) It > >would therefore not be possible to pass both states to the printf() function > >as parameters in the same call. The only way your reasoning could work is if > >printf() were to call strref(str) having processed the first %s and, of > >cource, that is not how any function works. > > > >Tim > > wrote in message > >news:vhpart0gjqnr7u2tf0ih8hdf18mlkj11br AT 4ax DOT com... > >> OUTCH! you believe this behavior is correct, too? > >> > >> OMG! > >> > >> ...and still no incorporation of strrev(NO_ARGS); > >> > >> psst: that returns the last static value of a func, in this > >> case, whatever the last string that was "reversed" > >> (and no, its not a C++ thingy either; but all this is another story) > >> > >> On Sat, 29 Sep 2001 04:54:12 GMT, Les Cargill > >> wrote: > >> > >> >Radical, let us look at what is meant by the code snippet: > >> >printf("Original String: %s\nReversed String:%s\n", s, strrev(s)); > >> > > >> > > >> >First*, s is pushed on the stack, then "strrev" is called. > >> >strrev reversed the original string in place. > >> > > >> >Next**, the pointer return from strrev, and s ( which *are the same > >value* ) > >> >are both pushed on the stack > >> > > >> >Radical, NetSurfer wrote: > >> >> > >> >> On Sat, 29 Sep 2001 00:28:28 GMT, CBFalconer > >> >> wrote: > >> >> > >> >> >"A. Sinan Unur" wrote: > >> >> >> > >> >> >> Radical NetSurfer wrote in > >> >> >> news:lcq8rtk1nqua2hc6rqfhmqisbd587n8t2n AT 4ax DOT com: > >> >> >> > >> >> >> > I would like to encourage everyone who has a need for > >> >> >> > strrev to come forward and encourage the maintainers of > >> >> >> > LIBC used with GCC to kindly add strrev. > >> >> >> > >> >> >> Count me against this if for no other reason that the fact that I do > >not > >> >> >> like extra nonstandard function which solve tiny problems. If you > >need the > >> >> >> functionality, you can write one for your own situation. If it is > >going to > >> >> >> be added to a library, the solution needs to be useful to more than > >just > >> >> >> one person in a particular situation. > >> >> >> > >> >> >> Anyway, the main point of my post, however, is to point out just one > >of the > >> >> >> gotchas with these kinds of functions. > >> >> >> > >> >> >> You give the following usage example: > >> >> >> > >> >> >> > Example > >> >> >> > printf("The reverse of %s is %s\n", str, strrev(str) ); > >> >> >> > >> >> >> Hmmmmm ..... let us see using the code you suggested: > >> >> >> > >> >> >> /* +++Date last modified: 05-Jul-1997 */ > >> >> >> /* > >> >> >> ** STRREV.C - reverse a string in place > >> >> >> ** > >> >> >> ** public domain by Bob Stout > >> >> >> */ > >> >> >> > >> >> >> #include > >> >> >> #include > >> >> >> #include > >> >> >> > >> >> >> char *strrev(char *str) { > >> >> >> char *p1, *p2; > >> >> >> > >> >> >> if (! str || ! *str) return str; > >> >> >> for (p1 = str, p2 = str + strlen(str) - 1; p2 > p1; > >++p1, --p2) > >> >> >> { > >> >> >> *p1 ^= *p2; > >> >> >> *p2 ^= *p1; > >> >> >> *p1 ^= *p2; > >> >> >> } > >> >> >> return str; > >> >> >> } > >> >> >> > >> >> >> int main(void) > >> >> >> { > >> >> >> char s[] = "This is a test."; > >> >> >> printf("Original String: %s\nReversed String:%s\n", s, > >strrev(s)); > >> >> >> return 0; > >> >> >> } > >> >> >> > >> >> >> C:\var>gcc djstrrev.c -o djstrrev.exe -O2 -Wall > >> >> >> > >> >> >> C:\var>djstrrev > >> >> >> Original String: .tset a si sihT > >> >> >> Reversed String: .tset a si sihT > >> >> > >> >> If your compiler actually outputs both strings as reversed, > >> >> THEN I am very scared your compiler is quite BROKEN. > >> >> > >> >> printf("format specifier1, format_specififer2", var1, func1); > >> >> > >> >> does: > >> >> display __current__ value of var1 FIRST using format_specifier1, > >> >> __THEN__ > >> >> display __output__ of funct1 using format_specifier2, > >> >> > >> >> If DJGPP is not doing even this trivial behavior correctly, > >> >> Borland programs would never port correctly, > >> >> neither would anything else for that matter. > >> >> > >> >> Left to right, in the order AND STATE ENCOUNTERED! > >> >> > >> >> ....however... __AFTER__ the call to printf(), __THEN__ > >> >> 'str' will contain the result of the function call; > >> >> but __NEVER__ from __WITHIN__ the printf as > >> >> you implied. Your post is VERY MISLEADING. > >> >> > >> >> >> Now, think about that. > >> >> > > >> >> >Thank you. I knew there was a reason I made my equivalent > >> >> >(revstring) a void function. I just didn't know what it was :-) > >> > > >