473,396 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

brain teasers

how can two variables be swapped without using a third variable?

Apr 4 '07
95 4208
On Apr 5, 9:39 pm, Ian Collins <ian-n...@hotmail.comwrote:
user923005 wrote:
On Apr 5, 9:05 pm, Ian Collins <ian-n...@hotmail.comwrote:
>user923005 wrote:
>>On Apr 5, 8:48 pm, Ian Collins <ian-n...@hotmail.comwrote:
>>>user923005 wrote:
>>>>Having thought about this a bit, I think the superiority of the C++
template just got a huge hole shot in its foot, unless we make the
exchange a class member that stores a temporary, or unless we pass the
temporary in as a parameter. After all, the template exchange method
(if the temp is not part of the class) is going to do a new/delete
when we create the temp to perform the exchange.
>>>OK, I've kept out of this so far, but that assumption is wrong. The
temporary is just another automatic variable. Thus the C++ template
solution suffers the same potential stack exhaustion problems as my VLA
suggestion.
>>When you create a temporary, it will call the constructor. Typically,
the constructor will call new. You are right in the case of
fundamental types like integers and doubles.
>No, it will not.
><OT>Constructors don't call new, new calls constructors.</OT>
<OT>
Are you saying that using the new operator in constructors and the
delete operator in destructors is unusual?
It's not.

You're implying the object to be swapped are something other than valid
C types.</OT>
Right, hence my comment:
"You are right in the case of fundamental types like integers and
doubles."

If the the objects being swapped require complex initialisation (C or
C++), you probably wouldn't be swapping then, you'd more likely swap
pointers.
How will one perform an exchange without a temporary, even when we are
using pointers?
--
Ian Collins.- Hide quoted text -

- Show quoted text -

Apr 6 '07 #51
At about the time of 4/5/2007 4:38 PM, Coos Haak stated the following:
Op Thu, 05 Apr 2007 22:08:12 GMT schreef Daniel Rudy:
>At about the time of 4/5/2007 2:05 PM, Ian Collins stated the following:
>>Daniel Rudy wrote:
<snip>
>>> return(0);
return isn't a function. Why not make the function void?
It needs to return an error indicator to the caller if malloc fails?

Perhaps, but you haven't answered why do you think return is a function?!
I know that return is a keyword for C, But I always code it that way
because that is how I was taught.
--
Daniel Rudy

Email address has been base64 encoded to reduce spam
Decode email address using b64decode or uudecode -m

Why geeks like computers: look chat date touch grep make unzip
strip view finger mount fcsk more fcsk yes spray umount sleep
Apr 6 '07 #52
At about the time of 4/5/2007 8:48 PM, Ian Collins stated the following:
user923005 wrote:
>Having thought about this a bit, I think the superiority of the C++
template just got a huge hole shot in its foot, unless we make the
exchange a class member that stores a temporary, or unless we pass the
temporary in as a parameter. After all, the template exchange method
(if the temp is not part of the class) is going to do a new/delete
when we create the temp to perform the exchange.
OK, I've kept out of this so far, but that assumption is wrong. The
temporary is just another automatic variable. Thus the C++ template
solution suffers the same potential stack exhaustion problems as my VLA
suggestion. On the other hand, not having to pass things via void*
gives the compiler a better shot at optimising the copies.

The same applies to sorting in general, this is one area where C++
(through aggressive optimisation) can outperform C where templates
rather than void* are used to provide a generic solution.

Man, you guys are flat ruthless on my coding algorithms and style. My
original one was shot down, then my malloc one caused an argument... In
taking everyone's suggestions into account. I have devised the
following routine:

void swap(void *a, void *b, size_t size)
{
size_t i; /* generic counter */
unsigned char tmp; /* temp */
unsigned char *d1, *d2; /* data pointers */

d1 = a;
d2 = b;
for (i = 0; i < size; i++)
{
tmp = *d1;
*d1 = *d2;
*d2 = tmp;
if (i < (size - 1))
{
d1++;
d2++;
}
}
return;
}
That one doesn't use malloc, swaps 1 byte at a time, and can be used
with any datatype. It will not increment d1 and d2 beyond the size either.
--
Daniel Rudy

Email address has been base64 encoded to reduce spam
Decode email address using b64decode or uudecode -m

Why geeks like computers: look chat date touch grep make unzip
strip view finger mount fcsk more fcsk yes spray umount sleep
Apr 6 '07 #53
Daniel Rudy said:

<snip>
Man, you guys are flat ruthless on my coding algorithms and style. My
original one was shot down, then my malloc one caused an argument...
Don't you think that's a good thing?

All of us have been shot down in flames a few times here in c.l.c, and
it has generally been a useful experience.
In
taking everyone's suggestions into account. I have devised the
following routine:

void swap(void *a, void *b, size_t size)
You'll need a header for that size_t.
{
size_t i; /* generic counter */
unsigned char tmp; /* temp */
unsigned char *d1, *d2; /* data pointers */

d1 = a;
d2 = b;
for (i = 0; i < size; i++)
{
tmp = *d1;
Your indenting is broken. <g,d&rvf>
That one doesn't use malloc, swaps 1 byte at a time, and can be used
with any datatype. It will not increment d1 and d2 beyond the size
either.
I think you could profitably swap more bytes at a time than that, using
memcpy. Who told you swapping many bytes at once was a bad idea?

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Apr 6 '07 #54
Daniel Rudy said:
I know that return is a keyword for C, But I always code it that way
because that is how I was taught.
Fair (enough).

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Apr 6 '07 #55
On Apr 6, 1:58 am, Ian Collins <ian-n...@hotmail.comwrote:
Daniel Rudy wrote:
At about the time of 4/5/2007 4:10 AM, Army1987 stated the following:
if (sizeof *a != sizeof *b) {
I think you mean sizeof(*a) and sizeof(*b), but does that construct even
work for a void *?

No, you can't take the sizeof void.
[Gunv@nt@ps4064(linux):dumps]$cat test.c
#include <stdio.h>

int main() {
void *p;
printf("Sizeof p : %d\n", sizeof p);
printf("Sizeof *p : %d\n", sizeof *p);
printf("Sizeof void : %d\n", sizeof(void));
return 0;
}

[Gunv@nt@ps4064(linux):dumps]$./out
Sizeof p : 4
Sizeof *p : 1
Sizeof void : 1
>
--
Ian Collins.
-Cheers,
Gunvant
~~~~~~~~
No trees were killed in the sending of this message. However a large
number of electrons were terribly inconvenienced.
Apr 6 '07 #56
Gunvant Patil said:
On Apr 6, 1:58 am, Ian Collins <ian-n...@hotmail.comwrote:
>>
No, you can't take the sizeof void.

[Gunv@nt@ps4064(linux):dumps]$cat test.c
#include <stdio.h>

int main() {
void *p;
printf("Sizeof p : %d\n", sizeof p);
printf("Sizeof *p : %d\n", sizeof *p);
printf("Sizeof void : %d\n", sizeof(void));
return 0;
}
foo.c:3: warning: function declaration isn't a prototype
foo.c: In function `main':
foo.c:6: warning: sizeof applied to a void type
foo.c:7: warning: sizeof applied to a void type

Translation: you have been warned. If you choose to proceed regardless,
on your own head be it.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Apr 6 '07 #57
"Gunvant Patil" <gu*************@gmail.comwrites:
On Apr 6, 1:58 am, Ian Collins <ian-n...@hotmail.comwrote:
[...]
>No, you can't take the sizeof void.

[Gunv@nt@ps4064(linux):dumps]$cat test.c
#include <stdio.h>

int main() {
void *p;
printf("Sizeof p : %d\n", sizeof p);
printf("Sizeof *p : %d\n", sizeof *p);
printf("Sizeof void : %d\n", sizeof(void));
return 0;
}

[Gunv@nt@ps4064(linux):dumps]$./out
Sizeof p : 4
Sizeof *p : 1
Sizeof void : 1
% gcc -ansi -pedantic test.c
test.c: In function `main':
test.c:6: warning: invalid application of `sizeof' to a void type
test.c:7: warning: invalid application of `sizeof' to a void type

gcc allows certain operations on void, including sizeof, as an
extension. When you invoke gcc in conforming mode, it correctly
issues the required diagnostic for this constraint violation.

The point of the extension is to allow arithmetic on void* as if it
were char*.

In standard C, you can't compute sizeof (void).

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Apr 6 '07 #58
"Gunvant Patil" <gu*************@gmail.comwrote:
On Apr 6, 1:58 am, Ian Collins <ian-n...@hotmail.comwrote:
No, you can't take the sizeof void.

[Gunv@nt@ps4064(linux):dumps]$cat test.c
#include <stdio.h>

int main() {
void *p;
printf("Sizeof p : %d\n", sizeof p);
printf("Sizeof *p : %d\n", sizeof *p);
printf("Sizeof void : %d\n", sizeof(void));
return 0;
}

[Gunv@nt@ps4064(linux):dumps]$./out
Sizeof p : 4
Sizeof *p : 1
Sizeof void : 1
Ganuck extensions have no mandatory power outside Ganuck. In _C_, you
can't take sizeof of void.

Richard
Apr 6 '07 #59
On Apr 6, 1:22 pm, Richard Heathfield <r...@see.sig.invalidwrote:
Gunvant Patil said:
On Apr 6, 1:58 am, Ian Collins <ian-n...@hotmail.comwrote:
No, you can't take the sizeof void.
[Gunv@nt@ps4064(linux):dumps]$cat test.c
#include <stdio.h>
int main() {
void *p;
printf("Sizeof p : %d\n", sizeof p);
printf("Sizeof *p : %d\n", sizeof *p);
printf("Sizeof void : %d\n", sizeof(void));
return 0;
}

foo.c:3: warning: function declaration isn't a prototype
foo.c: In function `main':
foo.c:6: warning: sizeof applied to a void type
foo.c:7: warning: sizeof applied to a void type

Translation: you have been warned. If you choose to proceed regardless,
on your own head be it.
Yikes..!!! it didn't shown me any warnings when i build that binary
using -Wall.

[Gunv@nt@ps4064(linux):dumps]$gcc -Wall -o out test.c
[Gunv@nt@ps4064(linux):dumps]$gcc -v
Using built-in specs.
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --
infodir=/usr/share/info --enable-shared --enable-threads=posix --
enable-checking=release --with-system-zlib --enable-__cxa_atexit --
disable-libunwind-exceptions --enable-libgcj-multifile --enable-
languages=c,c++,objc,java,f95,ada --enable-java-awt=gtk --with-java-
home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --host=i386-redhat-linux
Thread model: posix
gcc version 4.0.0 20050519 (Red Hat 4.0.0-8)
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999http://www.cpax.org.uk
email: rjh at the above domain, - www.

-Cheers,
Gunvant
~~~~~~~~
No trees were killed in the sending of this message. However a large
number of electrons were terribly inconvenienced.
Apr 6 '07 #60
Gunvant Patil said:
On Apr 6, 1:22 pm, Richard Heathfield <r...@see.sig.invalidwrote:
>>
foo.c:3: warning: function declaration isn't a prototype
foo.c: In function `main':
foo.c:6: warning: sizeof applied to a void type
foo.c:7: warning: sizeof applied to a void type

Translation: you have been warned. If you choose to proceed
regardless, on your own head be it.

Yikes..!!! it didn't shown me any warnings when i build that binary
using -Wall.
That should be adequate proof, if proof were needed, that gcc's -Wall
does *not* mean "enable all warnings".

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Apr 6 '07 #61
Daniel Rudy wrote, On 06/04/07 07:11:
At about the time of 4/5/2007 8:48 PM, Ian Collins stated the following:
>user923005 wrote:
>>Having thought about this a bit, I think the superiority of the C++
template just got a huge hole shot in its foot, unless we make the
exchange a class member that stores a temporary, or unless we pass the
temporary in as a parameter. After all, the template exchange method
(if the temp is not part of the class) is going to do a new/delete
when we create the temp to perform the exchange.
OK, I've kept out of this so far, but that assumption is wrong. The
temporary is just another automatic variable. Thus the C++ template
solution suffers the same potential stack exhaustion problems as my VLA
suggestion. On the other hand, not having to pass things via void*
gives the compiler a better shot at optimising the copies.

The same applies to sorting in general, this is one area where C++
(through aggressive optimisation) can outperform C where templates
rather than void* are used to provide a generic solution.

Man, you guys are flat ruthless on my coding algorithms and style.
Yes, which is a good thing.
My
original one was shot down, then my malloc one caused an argument...
People here like arguing (in the sense of debating rather than shouting
matches). It can be fun.
In
taking everyone's suggestions into account. I have devised the
following routine:

void swap(void *a, void *b, size_t size)
{
size_t i; /* generic counter */
Please do not use tabs when posting to news groups. Sometimes they get
stripped from posts.
unsigned char tmp; /* temp */
unsigned char *d1, *d2; /* data pointers */

d1 = a;
d2 = b;
You could have done the initialising on declaration
unsigned char *d1 = a;
unsigned char *d2 = b;
for (i = 0; i < size; i++)
{
tmp = *d1;
*d1 = *d2;
*d2 = tmp;
if (i < (size - 1))
{
d1++;
d2++;
}
}
return;
}

That one doesn't use malloc, swaps 1 byte at a time, and can be used
with any datatype. It will not increment d1 and d2 beyond the size either.
You do not need to worry about that last point since C explicitly allows
it. So here is my tidied up version...
void swap(void *a, void *b, size_t size)
{
unsigned char tmp;
unsigned char *d1 = a;
unsigned char *d2 = b;

while (size 0) {
tmp = *d1;
*d1++ = *d2;
*d2++ = tmp;
size--;
}
}

Or, to be a bit cleverer and do block copies

void swap(void *a, void *b, size_t size)
{
unsigned char tmp[64];
unsigned char *d1 = a;
unsigned char *d2 = b;

while (size >= sizeof tmp) {
memcpy(tmp, d1, sizeof tmp);
memcpy(d1, d2, sizeof tmp);
memcpy(d2, tmp, sizeof tmp);
size -= sizeof tmp;
d1 += sizeof tmp;
d2 += sizeof tmp;
}

if (size 0) {
memcpy(tmp, d1, size);
memcpy(d1, d2, size);
memcpy(d2, tmp, size);
}
}

Or to get those benefits without calling memcpy, abuse structs:

void swapstr(void *a, void *b, size_t size)
{
struct buf {
unsigned char arr[64];
};
struct buf tmp;
struct buf *d1 = a;
struct buf *d2 = b;

while (size >= sizeof tmp) {
tmp = *d1;
*d1++ = *d2;
*d2++ = tmp;
size -= sizeof tmp;
}

while (size 0) {
tmp = *d1;
*d1++ = *d2;
*d2++ = tmp;
size--;
}
}

Of course, which is most efficient will depend. Personally I've never
had to worry about the efficiency of swapping.
--
Flash Gordon
It will copy any size and you can tune the size of your temporary for
optimal performance.
Apr 6 '07 #62
At about the time of 4/6/2007 12:37 AM, Richard Heathfield stated the
following:
Daniel Rudy said:

<snip>
>Man, you guys are flat ruthless on my coding algorithms and style. My
original one was shot down, then my malloc one caused an argument...

Don't you think that's a good thing?
In most cases, yes. In fact, I've actually learned alot of stuff by it.
But, beyond that it's just nitpicking which gets annoying... :/
All of us have been shot down in flames a few times here in c.l.c, and
it has generally been a useful experience.
Agreed.
>In
taking everyone's suggestions into account. I have devised the
following routine:

void swap(void *a, void *b, size_t size)

You'll need a header for that size_t.
True, and I'm sure that most people are aware of it.
> {
size_t i; /* generic counter */
unsigned char tmp; /* temp */
unsigned char *d1, *d2; /* data pointers */

d1 = a;
d2 = b;
for (i = 0; i < size; i++)
{
tmp = *d1;

Your indenting is broken. <g,d&rvf>
This is a matter of style. When I code using my tools, that's the
indenting that I use. When I code on the fly in the group, I generally
use tabs to indent. Look at some of my past posts in the group, even in
this thread.
>That one doesn't use malloc, swaps 1 byte at a time, and can be used
with any datatype. It will not increment d1 and d2 beyond the size
either.

I think you could profitably swap more bytes at a time than that, using
memcpy. Who told you swapping many bytes at once was a bad idea?
I think it was user923005 who said something about performance...And I
believe it was Keith T. who mentioned swapping one byte at a time.
--
Daniel Rudy

Email address has been base64 encoded to reduce spam
Decode email address using b64decode or uudecode -m

Why geeks like computers: look chat date touch grep make unzip
strip view finger mount fcsk more fcsk yes spray umount sleep
Apr 6 '07 #63
Ian Collins wrote:
Army1987 wrote:
>"Ian Collins" <ia******@hotmail.comha scritto nel messaggio
news:57*************@mid.individual.net...
>>Or even in modern C:

void swap( void *a, void *b, size_t size )
{
char temp[size];

memcpy(temp, a, size);
memcpy(a, b, size);
memcpy(b, temp, size);
}
How 'bout:
int swap (void *a, void *b)
{
void *temp;
if (sizeof *a != sizeof *b) {

Have you tried to compile this?
> retun 0;

Or this?
I doubt it.

"/tmp/foo.c", line 4: error: operand of "sizeof" cannot have incomplete type
if (sizeof *a != sizeof *b) {
^
"/tmp/foo.c", line 4: error: operand of "sizeof" cannot have incomplete type
if (sizeof *a != sizeof *b) {
^
"/tmp/foo.c", line 5: error: identifier "fputs" is not defined
fputs("Attempt to swap variables of incompatible types", stderr);
^
"/tmp/foo.c", line 5: error: identifier "stderr" is not defined
fputs("Attempt to swap variables of incompatible types", stderr);
^
"/tmp/foo.c", line 8: error: identifier "malloc" is not defined
temp = malloc(sizeof *a);
^
"/tmp/foo.c", line 8: error: operand of "sizeof" cannot have incomplete type
temp = malloc(sizeof *a);
^
"/tmp/foo.c", line 9: error: identifier "NULL" is not defined
if (temp == NULL) {
^
"/tmp/foo.c", line 10: error: identifier "perror" is not defined
perror("Unable to allocate memory");
^
"/tmp/foo.c", line 13: error: identifier "memcpy" is not defined
memcpy(temp, a, sizeof *a);
^
"/tmp/foo.c", line 13: error: operand of "sizeof" cannot have incomplete
type
memcpy(temp, a, sizeof *a);
^
"/tmp/foo.c", line 14: error: identifier "memcpy" is not defined
memcpy(a, b, sizeof *a);
^
"/tmp/foo.c", line 14: error: operand of "sizeof" cannot have incomplete
type
memcpy(a, b, sizeof *a);
^
"/tmp/foo.c", line 15: error: identifier "memcpy" is not defined
memcpy(b, temp, sizeof *a);
^
"/tmp/foo.c", line 15: error: operand of "sizeof" cannot have incomplete
type
memcpy(b, temp, sizeof *a);
^
"/tmp/foo.c", line 16: error: identifier "free" is not defined
free(temp);
^
"/tmp/foo.c", line 17: error: identifier "retun" is not defined
retun 0;
^
"/tmp/foo.c", line 17: error: expected ';'
retun 0;
^
"/tmp/foo.c", line 18: warning: function "swap" should return a value
}
^

17 errors found compiling "/tmp/foo.c".

Apr 6 '07 #64
Ian Collins wrote:
Army1987 wrote:
>"Ian Collins" <ia******@hotmail.comha scritto nel messaggio
news:57*************@mid.individual.net...
>>Or even in modern C:

void swap( void *a, void *b, size_t size )
{
char temp[size];

memcpy(temp, a, size);
memcpy(a, b, size);
memcpy(b, temp, size);
}
How 'bout:
int swap (void *a, void *b)
{
void *temp;
if (sizeof *a != sizeof *b) {

Have you tried to compile this?
> retun 0;

Or this?
One doubts it.

"/tmp/foo.c", line 4: error: operand of "sizeof" cannot have incomplete type
if (sizeof *a != sizeof *b) {
^
"/tmp/foo.c", line 4: error: operand of "sizeof" cannot have incomplete type
if (sizeof *a != sizeof *b) {
^
"/tmp/foo.c", line 5: error: identifier "fputs" is not defined
fputs("Attempt to swap variables of incompatible types", stderr);
^
"/tmp/foo.c", line 5: error: identifier "stderr" is not defined
fputs("Attempt to swap variables of incompatible types", stderr);
^
"/tmp/foo.c", line 8: error: identifier "malloc" is not defined
temp = malloc(sizeof *a);
^
"/tmp/foo.c", line 8: error: operand of "sizeof" cannot have incomplete type
temp = malloc(sizeof *a);
^
"/tmp/foo.c", line 9: error: identifier "NULL" is not defined
if (temp == NULL) {
^
"/tmp/foo.c", line 10: error: identifier "perror" is not defined
perror("Unable to allocate memory");
^
"/tmp/foo.c", line 13: error: identifier "memcpy" is not defined
memcpy(temp, a, sizeof *a);
^
"/tmp/foo.c", line 13: error: operand of "sizeof" cannot have incomplete
type
memcpy(temp, a, sizeof *a);
^
"/tmp/foo.c", line 14: error: identifier "memcpy" is not defined
memcpy(a, b, sizeof *a);
^
"/tmp/foo.c", line 14: error: operand of "sizeof" cannot have incomplete
type
memcpy(a, b, sizeof *a);
^
"/tmp/foo.c", line 15: error: identifier "memcpy" is not defined
memcpy(b, temp, sizeof *a);
^
"/tmp/foo.c", line 15: error: operand of "sizeof" cannot have incomplete
type
memcpy(b, temp, sizeof *a);
^
"/tmp/foo.c", line 16: error: identifier "free" is not defined
free(temp);
^
"/tmp/foo.c", line 17: error: identifier "retun" is not defined
retun 0;
^
"/tmp/foo.c", line 17: error: expected ';'
retun 0;
^
"/tmp/foo.c", line 18: warning: function "swap" should return a value
}
^

17 errors found compiling "/tmp/foo.c".

Apr 6 '07 #65
Daniel Rudy said:
At about the time of 4/6/2007 12:37 AM, Richard Heathfield stated the
following:
>Daniel Rudy said:
<snip>
>> d1 = a;
d2 = b;
for (i = 0; i < size; i++)
{
tmp = *d1;

Your indenting is broken. <g,d&rvf>

This is a matter of style. When I code using my tools, that's the
indenting that I use.
You outdent the bodies of for-loops to the left margin *on purpose*?
Well, okay, if that's what you want, but, er, why?
>I think you could profitably swap more bytes at a time than that,
using memcpy. Who told you swapping many bytes at once was a bad
idea?

I think it was user923005 who said something about performance...And I
believe it was Keith T. who mentioned swapping one byte at a time.
You might want to ask him why he suggested that. It sounds silly to me.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Apr 6 '07 #66
>Daniel Rudy said:
>This is a matter of style. When I code using my tools, that's the
indenting that I use.
In article <g_******************************@bt.com>
Richard Heathfield <rj*@see.sig.invalidwrote:
>You outdent the bodies of for-loops to the left margin *on purpose*?
Well, okay, if that's what you want, but, er, why?
I think you left out an important sentence here (maybe you did not
realize it was important): his tools put in a tab (as in '\t')
character.

This tab came through fine on *my* usenet server, so that the
inside of the loop was more-indented. It appears that whatever
software sits between you and Daniel Rudy, however, ate the tab.
The fact that some Usenet servers (and/or other Usenet article
delivery systems) eat tabs are why I have my software run all
my postings through the "expand" program by default.
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Apr 6 '07 #67
Richard Heathfield <rj*@see.sig.invalidwrites:
Gunvant Patil said:
>On Apr 6, 1:22 pm, Richard Heathfield <r...@see.sig.invalidwrote:
>>>
foo.c:3: warning: function declaration isn't a prototype
foo.c: In function `main':
foo.c:6: warning: sizeof applied to a void type
foo.c:7: warning: sizeof applied to a void type

Translation: you have been warned. If you choose to proceed
regardless, on your own head be it.

Yikes..!!! it didn't shown me any warnings when i build that binary
using -Wall.

That should be adequate proof, if proof were needed, that gcc's -Wall
does *not* mean "enable all warnings".
Indeed. "-pedantic" is the option you need to enable that warning.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Apr 6 '07 #68
On Thu, 05 Apr 2007 17:14:23 -0700, Keith Thompson wrote:
Coos Haak <ch*****@hccnet.nlwrites:
>Op Thu, 05 Apr 2007 22:08:12 GMT schreef Daniel Rudy:
>>At about the time of 4/5/2007 2:05 PM, Ian Collins stated the following:
Daniel Rudy wrote:
<snip>
>>>> return(0);

return isn't a function. Why not make the function void?

It needs to return an error indicator to the caller if malloc fails?

Perhaps, but you haven't answered why do you think return is a function?!

I see no real evidence that he thinks return is a function. It's more
likely that he either thinks (incorrectly) that a return statement
requires parentheses, or (questionably) that using parentheses is good
style. There is precedent for the latter point of view; see K&R1, for
example.

Personally, I strongly prefer not to use unnecessary parentheses on a
return statement, but of course "return(0);" is perfectly legal.
A lot of people - myself included - have developed a habit of using
parentheses in return. Why? Who knows? It's common enough it shouldn't
be confusing, even if it is redundant. I don't advocate redundancy in
general, but this is one of those harmless cases where nothing is really
lost in the use of it.
Apr 6 '07 #69
Richard Heathfield <rj*@see.sig.invalidwrites:
Daniel Rudy said:
>At about the time of 4/6/2007 12:37 AM, Richard Heathfield stated the
following:
[...]
>>I think you could profitably swap more bytes at a time than that,
using memcpy. Who told you swapping many bytes at once was a bad
idea?

I think it was user923005 who said something about performance...And I
believe it was Keith T. who mentioned swapping one byte at a time.

You might want to ask him why he suggested that. It sounds silly to me.
I suggested swapping one byte at a time as a generic alternative to
swapping entire objects at a time, which could run out of memory if
the objects being swapped are very large. Swapping medium-sized
chunks is likely to be more efficient, but it's also more complex; you
need to allow for the possibility that the object size isn't a
multiple of the chunk size, and determining the optimal chunk size is
extremely system-specific (and may depend on the alignments of the
objects being swapped).

In practice, swapping usually involves small objects. As someone has
already pointed out in this thread, if you need to swap large objects,
you're probably better off swapping pointers. And swapping is such a
simple operation that there isn't really a need to write a generic
swap routine; it's easy enough to code it directly, which lets the
compiler take advantage of the specific type being swapped.

int x, y;
...
{
/* swap x and y */
const int old_x = x;
x = y;
y = old_x;
}

On the other hand, there's some small risk of getting it wrong if
you're not careful (I initially wrote "y = x;", but I corrected it
immediately).

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Apr 6 '07 #70
Richard Heathfield wrote:
Daniel Rudy said:
At about the time of 4/6/2007 12:37 AM, Richard Heathfield stated
the following:
Daniel Rudy said:
<snip>
> d1 = a;
d2 = b;
for (i = 0; i < size; i++)
{
tmp = *d1;

Your indenting is broken. <g,d&rvf>
This is a matter of style. When I code using my tools, that's the
indenting that I use.

You outdent the bodies of for-loops to the left margin *on purpose*?
Well, okay, if that's what you want, but, er, why?
It didn't appear that way to me in Daniel's orginal posts, only in your
quotes.

Brian
Apr 6 '07 #71
Keith Thompson said:
Richard Heathfield <rj*@see.sig.invalidwrites:
>Daniel Rudy said:
>>>
I think it was user923005 who said something about performance...And
I believe it was Keith T. who mentioned swapping one byte at a time.

You might want to ask him why he suggested that. It sounds silly to
me.

I suggested swapping one byte at a time as a generic alternative to
swapping entire objects at a time, which could run out of memory if
the objects being swapped are very large.
Okay, that sounds fair enough, although...
Swapping medium-sized
chunks is likely to be more efficient,
Indeed.
but it's also more complex;
Only a bit.
you need to allow for the possibility that the object size isn't a
multiple of the chunk size,
That's easy enough.
and determining the optimal chunk size is
extremely system-specific (and may depend on the alignments of the
objects being swapped).
But you don't actually need to do this, at least not if the alternative
is single-byte swapping! You can bet your best friend's mother's
cousin's accountant's shirt that pretty well any finger-in-the-air
chunk size is going to be better than 1.
In practice, swapping usually involves small objects. As someone has
already pointed out in this thread, if you need to swap large objects,
you're probably better off swapping pointers.
Aye.
And swapping is such a
simple operation that there isn't really a need to write a generic
swap routine;
Ha! Yeah, I thought that too once. :-) But I ended up finding a need.
Either that, or I under-analysed the problem (or, just perhaps,
over-analysed it).

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Apr 6 '07 #72
Default User said:
Richard Heathfield wrote:
>You outdent the bodies of for-loops to the left margin *on purpose*?
Well, okay, if that's what you want, but, er, why?

It didn't appear that way to me in Daniel's orginal posts, only in
your quotes.
Oh. Tabs again, I guess. Nothing to see here, move along...

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Apr 6 '07 #73
"Gunvant Patil" <gu*************@gmail.comwrote in message
news:11**********************@y66g2000hsf.googlegr oups.com...
Yikes..!!! it didn't shown me any warnings when i build that binary
using -Wall.
You need to use "-ansi -pedantic -W -Wall" to get everything.

I'll leave understanding the rationale of -Wall not including all warnings
as an exercise for the reader :)

S

--
Stephen Sprunk "Those people who think they know everything
CCIE #3723 are a great annoyance to those of us who do."
K5SSS --Isaac Asimov
--
Posted via a free Usenet account from http://www.teranews.com

Apr 6 '07 #74
Richard Heathfield wrote:
Default User said:
Richard Heathfield wrote:
You outdent the bodies of for-loops to the left margin *on
purpose*?
It didn't appear that way to me in Daniel's orginal posts, only in
your quotes.

Oh. Tabs again, I guess. Nothing to see here, move along...
Possibly, I suppose. The indents were pretty small though.

Brian

Apr 6 '07 #75
Keith Thompson wrote, On 06/04/07 19:51:
Richard Heathfield <rj*@see.sig.invalidwrites:
>Gunvant Patil said:
>>On Apr 6, 1:22 pm, Richard Heathfield <r...@see.sig.invalidwrote:
foo.c:3: warning: function declaration isn't a prototype
foo.c: In function `main':
foo.c:6: warning: sizeof applied to a void type
foo.c:7: warning: sizeof applied to a void type

Translation: you have been warned. If you choose to proceed
regardless, on your own head be it.
Yikes..!!! it didn't shown me any warnings when i build that binary
using -Wall.
That should be adequate proof, if proof were needed, that gcc's -Wall
does *not* mean "enable all warnings".

Indeed. "-pedantic" is the option you need to enable that warning.
You also need -ansi to get some of the others warnings you should want.
If you want as close as gcc comes to C99 look in the manual and also
look up the limitations.
--
Flash Gordon
Apr 6 '07 #76
Stephen Sprunk wrote:
>
.... snip ...
>
You need to use "-ansi -pedantic -W -Wall" to get everything.

I'll leave understanding the rationale of -Wall not including all
warnings as an exercise for the reader :)
I suspect it is historic. At one point -Wall enabled all. Then
more were needed. In order to not disturb old makefiles, -W was
added.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>

"A man who is right every time is not likely to do very much."
-- Francis Crick, co-discover of DNA
"There is nothing more amazing than stupidity in action."
-- Thomas Matthews

--
Posted via a free Usenet account from http://www.teranews.com

Apr 7 '07 #77
Richard Heathfield wrote:
Daniel Rudy said:

<snip>
>#define MAXSWAP 32 /* maximum size of variable swap */
int swap(void *a, void *b, int size)
{
char temp[MAXSWAP]; /* temp buffer */

if (size MAXSWAP) return(-1);
memcpy(temp, a, size);
memcpy(a, b, size);
memcpy(b, temp, size);
return(0);
}

Now what's wrong with that?

Not very much. Here's a less restrictive solution:

#include <string.h>

#define MAXSWAP 32

void swap(void *va, void *vb, size_t size)
{
unsigned char *a = va;
unsigned char *b = vb;
unsigned char temp[MAXSWAP] = {0};

while(size >= MAXSWAP)
{
memcpy(temp, a, MAXSWAP);
memcpy(a, b, MAXSWAP);
memcpy(b, temp, MAXSWAP);
size -= MAXSWAP;
a += MAXSWAP;
b += MAXSWAP;
}
memcpy(temp, a, size);
memcpy(a, b, size);
memcpy(b, temp, size);
return;
}

It is possible that this could be done more elegantly (eliminating
the duplicated code). Given the time of day here, I'll leave that
as an exercise.
Being a believer in the KISS principle, I would write it as:

void swap(void *va, void *vb, size_t size) {
unsigned char *a = va;
unsigned char *b = vb;
unsigned char t;

if (va != vb)
while (size--) {
t = *a; *a++ = *b; *b++ = t;
}
}

and let the compiler optimize. I would not alter swap unless
profiling showed it to be a critical cpu eater. I might even
eliminate the va != vb test. If I kept it I would move the
initialization of a and b to after the test.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>

"A man who is right every time is not likely to do very much."
-- Francis Crick, co-discover of DNA
"There is nothing more amazing than stupidity in action."
-- Thomas Matthews

--
Posted via a free Usenet account from http://www.teranews.com

Apr 7 '07 #78
Stephen Sprunk said:
"Gunvant Patil" <gu*************@gmail.comwrote in message
news:11**********************@y66g2000hsf.googlegr oups.com...
>Yikes..!!! it didn't shown me any warnings when i build that binary
using -Wall.

You need to use "-ansi -pedantic -W -Wall" to get everything.
That still doesn't give you everything.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Apr 7 '07 #79
Richard Heathfield <rj*@see.sig.invalidwrites:
Stephen Sprunk said:
>"Gunvant Patil" <gu*************@gmail.comwrote in message
news:11**********************@y66g2000hsf.googleg roups.com...
>>Yikes..!!! it didn't shown me any warnings when i build that binary
using -Wall.

You need to use "-ansi -pedantic -W -Wall" to get everything.

That still doesn't give you everything.
Well, that's good, because I don't know where I'd put it.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Apr 7 '07 #80
On Apr 4, 3:42 pm, "viv342" <viv...@gmail.comwrote:
how can two variables be swapped without using a third variable?
a=a+b;
b=a-b;
a=a-b;
however we may not be able to swap pointers this way.

Apr 7 '07 #81
"saki" <sa***********@gmail.comwrites:
On Apr 4, 3:42 pm, "viv342" <viv...@gmail.comwrote:
>how can two variables be swapped without using a third variable?

a=a+b;
b=a-b;
a=a-b;
however we may not be able to swap pointers this way.
Somebody already suggested this. For signed integers, it doesn't work
if there's an overflow. For floating-point numbers, it can fail due
to either overflow or rounding errors. For anything non-numeric, it
just doesn't work.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Apr 7 '07 #82
saki wrote:
On Apr 4, 3:42 pm, "viv342" <viv...@gmail.comwrote:
>how can two variables be swapped without using a third variable?

a=a+b;
b=a-b;
a=a-b;
however we may not be able to swap pointers this way.
Or even integers, whether short or long or long long, whether signed or
unsigned,
or floating point numbers, whether float or double or long double.
There is _no_ type for which yours is an answer. That makes it worth
even less than the silly XOR trick.
Apr 7 '07 #83
At about the time of 4/6/2007 10:34 AM, Chris Torek stated the following:
>Daniel Rudy said:
>>This is a matter of style. When I code using my tools, that's the
indenting that I use.

In article <g_******************************@bt.com>
Richard Heathfield <rj*@see.sig.invalidwrote:
>You outdent the bodies of for-loops to the left margin *on purpose*?
Well, okay, if that's what you want, but, er, why?

I think you left out an important sentence here (maybe you did not
realize it was important): his tools put in a tab (as in '\t')
character.

This tab came through fine on *my* usenet server, so that the
inside of the loop was more-indented. It appears that whatever
software sits between you and Daniel Rudy, however, ate the tab.
The fact that some Usenet servers (and/or other Usenet article
delivery systems) eat tabs are why I have my software run all
my postings through the "expand" program by default.
When I write my code on the Unix system, this is how I indent my code:

void swap(void *a, void *b, size_t size)
{
size_t i; /* generic counter */
unsigned char tmp; /* temp */
unsigned char *d1, *d2; /* data pointers */

d1 = a;
d2 = b;
for (i = 0; i < size; i++)
{
tmp = *d1;
*d1 = *d2;
*d2 = tmp;
if (i < (size - 1))
{
d1++;
d2++;
}
}
return;
}

When I code on the fly here in the group, it's just easier to do it this
way:

#define MAXSWAP 32 /* maximum size of variable swap */
int swap(void *a, void *b, int size)
{
char temp[MAXSWAP]; /* temp buffer */

if (size MAXSWAP) return(-1);
memcpy(temp, a, size);
memcpy(a, b, size);
memcpy(b, temp, size);
return(0);
}
Now if your software is stripping tabs off, there's not much I can do
about it, Richard Heathfield.

--
Daniel Rudy

Email address has been base64 encoded to reduce spam
Decode email address using b64decode or uudecode -m

Why geeks like computers: look chat date touch grep make unzip
strip view finger mount fcsk more fcsk yes spray umount sleep
Apr 7 '07 #84
At about the time of 4/6/2007 1:35 PM, Default User stated the following:
Richard Heathfield wrote:
>Default User said:
>>Richard Heathfield wrote:

You outdent the bodies of for-loops to the left margin *on
purpose*?
>>It didn't appear that way to me in Daniel's orginal posts, only in
your quotes.

Oh. Tabs again, I guess. Nothing to see here, move along...

Possibly, I suppose. The indents were pretty small though.

Brian
About 2 space indents per block level.

#include <stdio.h>

int main(void)
{
printf("Hello World\n");
return(0);
}

--
Daniel Rudy

Email address has been base64 encoded to reduce spam
Decode email address using b64decode or uudecode -m

Why geeks like computers: look chat date touch grep make unzip
strip view finger mount fcsk more fcsk yes spray umount sleep
Apr 7 '07 #85
Daniel Rudy said:

<snip>
Now if your software is stripping tabs off, there's not much I can do
about it, Richard Heathfield.
Chris Torek has already explained how /he/ does something about it.

I stopped using tabs in C source years ago - I cannot now remember
whether Usenet was a factor in that decision, but it is not a decision
I have ever regretted.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Apr 7 '07 #86
Martin Ambuhl <ma*****@earthlink.netwrites:
saki wrote:
>On Apr 4, 3:42 pm, "viv342" <viv...@gmail.comwrote:
>>how can two variables be swapped without using a third variable?
a=a+b;
b=a-b;
a=a-b;
however we may not be able to swap pointers this way.

Or even integers, whether short or long or long long, whether signed
or unsigned,
or floating point numbers, whether float or double or long double.
There is _no_ type for which yours is an answer. That makes it worth
even less than the silly XOR trick.
I think it actually works for unsigned integers.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Apr 7 '07 #87
Daniel Rudy wrote, On 07/04/07 18:02:

<snip discussion of use of tabs in code posted to Usenet>
return(0);
}
Now if your software is stripping tabs off, there's not much I can do
about it, Richard Heathfield.
It almost certainly is not Richard's software but some news servers. It
may well not even be the news server Richard uses, merely some news
server between you and Richard.

The point is that it is a known problem that tabs are sometimes stripped
and so using tabs is a bad idea if you want your code to appear
formatted and/or you want people to read your posts.
--
Flash Gordon
Apr 7 '07 #88
Keith Thompson wrote:
Martin Ambuhl <ma*****@earthlink.netwrites:
>saki wrote:
>>On Apr 4, 3:42 pm, "viv342" <viv...@gmail.comwrote:
how can two variables be swapped without using a third variable?
a=a+b;
b=a-b;
a=a-b;
however we may not be able to swap pointers this way.
Or even integers, whether short or long or long long, whether signed
or unsigned,
or floating point numbers, whether float or double or long double.
There is _no_ type for which yours is an answer. That makes it worth
even less than the silly XOR trick.

I think it actually works for unsigned integers.
Not if a=a+b; would wrap.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Apr 7 '07 #89
Joe Wright said:
Keith Thompson wrote:
>Martin Ambuhl <ma*****@earthlink.netwrites:
>>saki wrote:
On Apr 4, 3:42 pm, "viv342" <viv...@gmail.comwrote:
how can two variables be swapped without using a third variable?
a=a+b;
b=a-b;
a=a-b;
however we may not be able to swap pointers this way.
Or even integers, whether short or long or long long, whether signed
or unsigned,
or floating point numbers, whether float or double or long double.
There is _no_ type for which yours is an answer. That makes it
worth even less than the silly XOR trick.

I think it actually works for unsigned integers.
Not if a=a+b; would wrap.
Well, let's see, using 8-bit unsigned integer types.

a = 200;
b = 56;

a = a + b; a -0
b = a - b; b -200
a = a - b; b -56

Looks good to me. (That is, I am suggesting that it does in fact work
for unsigned integer types. I am not trying to suggest that it is a
good technique.)

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Apr 7 '07 #90
Richard Heathfield wrote:
Daniel Rudy said:

<snip>
Now if your software is stripping tabs off, there's not much I can
do about it, Richard Heathfield.

Chris Torek has already explained how he does something about it.

I stopped using tabs in C source years ago - I cannot now remember
whether Usenet was a factor in that decision, but it is not a
decision I have ever regretted.

It was mandated by the first coding standard I worked to, but I can't
recall if I had come the same conclusion independently or not. I think
it's is the sensible approach, and many if not most text editors can be
set to do that, so it's really very little trouble.

Brian
Apr 7 '07 #91
Richard Heathfield wrote:
Joe Wright said:
>Keith Thompson wrote:
>>Martin Ambuhl <ma*****@earthlink.netwrites:
saki wrote:
On Apr 4, 3:42 pm, "viv342" <viv...@gmail.comwrote:
>how can two variables be swapped without using a third variable?
a=a+b;
b=a-b;
a=a-b;
however we may not be able to swap pointers this way.
Or even integers, whether short or long or long long, whether signed
or unsigned,
or floating point numbers, whether float or double or long double.
There is _no_ type for which yours is an answer. That makes it
worth even less than the silly XOR trick.
I think it actually works for unsigned integers.
Not if a=a+b; would wrap.

Well, let's see, using 8-bit unsigned integer types.

a = 200;
b = 56;

a = a + b; a -0
b = a - b; b -200
a = a - b; b -56

Looks good to me. (That is, I am suggesting that it does in fact work
for unsigned integer types. I am not trying to suggest that it is a
good technique.)
Yeah, I know. I was too fast on the 'send' switch. Apologies to Keith
and you and you and you.. :-)

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Apr 7 '07 #92
user923005 wrote:
On Apr 5, 9:39 pm, Ian Collins <ian-n...@hotmail.comwrote:
>>user923005 wrote:
>>>On Apr 5, 9:05 pm, Ian Collins <ian-n...@hotmail.comwrote:
>>>>user923005 wrote:
>>>>>On Apr 5, 8:48 pm, Ian Collins <ian-n...@hotmail.comwrote:
>>>>>>user923005 wrote:
>>>>>>>Having thought about this a bit, I think the superiority of the C++
>>>template just got a huge hole shot in its foot, unless we make the
>>>exchange a class member that stores a temporary, or unless we pass the
>>>temporary in as a parameter. After all, the template exchange method
>>>(if the temp is not part of the class) is going to do a new/delete
>>>when we create the temp to perform the exchange.
>>>>>>OK, I've kept out of this so far, but that assumption is wrong. The
>>temporary is just another automatic variable. Thus the C++ template
>>solution suffers the same potential stack exhaustion problems as my VLA
>>suggestion.
>>>>>When you create a temporary, it will call the constructor. Typically,
>the constructor will call new. You are right in the case of
>fundamental types like integers and doubles.
>>>>No, it will not.
>>>><OT>Constructors don't call new, new calls constructors.</OT>
>>><OT>
Are you saying that using the new operator in constructors and the
delete operator in destructors is unusual?
It's not.

You're implying the object to be swapped are something other than valid
C types.</OT>


Right, hence my comment:
"You are right in the case of fundamental types like integers and
doubles."
Or any struct that can be copied with a shallow copy.
--
Ian Collins.
Apr 9 '07 #93
In article <vk************@news.flash-gordon.me.ukFlash Gordon <sp**@flash-gordon.me.ukwrites:
Daniel Rudy wrote, On 07/04/07 18:02:
....
Now if your software is stripping tabs off, there's not much I can do
about it, Richard Heathfield.

It almost certainly is not Richard's software but some news servers. It
may well not even be the news server Richard uses, merely some news
server between you and Richard.
It almost certainly is the software. I surmise that Richard's software has
no tabstops set, and the software is just expanding tabs to the nearest
tabstop (which there is not), and so gets deleted on a reply and is not
seen when reading. See also very old discussions in net.lang.c about the
use of tabs in posted articles. When the reader uses tabstops different
from the poster's setting, the article can come out pretty mangled.

The use of tabs can be problematical for this reason, and that is also
why (I think) Default User had to expand tabs to spaces in his coding.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Apr 11 '07 #94
Dik T. Winter wrote:
In article <vk************@news.flash-gordon.me.ukFlash Gordon
<sp**@flash-gordon.me.ukwrites:
>It almost certainly is not Richard's software but some news servers.
>It may well not even be the news server Richard uses, merely some
news server between you and Richard.

It almost certainly is the software. I surmise that Richard's
software has no tabstops set, and the software is just expanding tabs
to the nearest tabstop (which there is not), and so gets deleted on a
reply and is not seen when reading. See also very old discussions in
net.lang.c about the use of tabs in posted articles. When the reader
uses tabstops different from the poster's setting, the article can
come out pretty mangled.

The use of tabs can be problematical for this reason, and that is also
why (I think) Default User had to expand tabs to spaces in his coding.
Originally it was mandated by the common coding standard I working to,
but I certainly saw the wisdom of it. I use spaces instead of tabs in
all my code, personal or otherwise, these days. All my text
editors/IDEs can substitute spaces for tab key strokes or auto-indents
when requested, which makes that easier.

Brian

Apr 11 '07 #95
On Fri, 6 Apr 2007 20:21:42 -0500, CBFalconer wrote
(in article <46***************@yahoo.com>):
Stephen Sprunk wrote:
>>
... snip ...
>>
You need to use "-ansi -pedantic -W -Wall" to get everything.

I'll leave understanding the rationale of -Wall not including all
warnings as an exercise for the reader :)

I suspect it is historic. At one point -Wall enabled all. Then
more were needed. In order to not disturb old makefiles, -W was
added.
Adding them both still does not yield all the warnings that are
available.
--
Randy Howard (2reply remove FOOBAR)
"The power of accurate observation is called cynicism by those
who have not got it." - George Bernard Shaw

Apr 19 '07 #96

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: brendan | last post by:
here's a brain teaser for someone with more skills or at least more lateral thinking capability than me - done my nut over this one... have written a list manager in PHP which a) posts out new...
7
by: robert | last post by:
running 8.1.7 server, 8.1.6 client. i *thought* inner join should not return nulls, but not only that, but i get way more rows than i'm expecting. assume: order table: order_number
7
by: Mark A | last post by:
If server 01 running HADR in the primary role crashes, and the DBA does a HADR takeover by force on the 02 server to switch roles, then the 02 server is now the primary. What happens when the...
3
by: Joachim Klassen | last post by:
Hi all, if I accidentally use a TAKEOVER command with BY FORCE clause while primary and standby are in peer state I'll end up with two primary's (at least with FP10 and Windows). Is this works ...
16
by: Ludwig | last post by:
Hi, I'm looking for C# brain teasers (or VB.NET): a little piece of code that does something special, or where a little error is. Does anyone has some of these, or links to sites? Thanks!
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.