Re: making bytes out of bits
- From: George <george@xxxxxxxxxxxxxxx>
- Date: Thu, 11 Dec 2008 01:38:37 -0700
On Wed, 10 Dec 2008 20:46:03 -0800, Barry Schwarz wrote:
On Wed, 10 Dec 2008 18:39:34 -0700, George <george@xxxxxxxxxxxxxxx>
wrote:
On Tue, 09 Dec 2008 18:12:31 -0800, Barry Schwarz wrote:
On Tue, 9 Dec 2008 03:36:53 -0700, George <george@xxxxxxxxxxxxxxx>
wrote:
char a[40]
char b[8][5];
char *p1;
char (*p2)[5];
p1 = a; /* legal because a is converted to char* */
p1 = b; /* illegal because b is converted to char(*)[5] */
p2 = b; /* legal as noted above */
p1 = (char*)b; /* legal because the cast changes the type */
Well, I tried to populate these arrays, but I get no output:
Since the compiler told you the code was broken, why did you even
bother to execute it?
And why are you repeatedly changing the topic of discussion but not
starting a new thread. You deliberately deleted the quote from your
message which asked the question my code tried to respond to. Your
question had nothing to do with the you posted below.
#include <stdio.h>
int main(void)
{
char a[40];
char b[8][5];
char *p1;
char (*p2)[5];
int i;
char c;
for (i=60; i = 60 + 40 ; ++ i)
How many times do you think this loop executes. Hint: it is not 40.
{
a[i-60] = i;
As a result of the error above, this statement invokes undefined
behavior.
}
for(i = 0; i = 40; ++ i)
{
putchar(a[i]);
}
putchar('\n');
p1 = a; /* legal because a is converted to char* */
p1 = b; /* illegal because b is converted to char(*)[5] */
p2 = b; /* legal as noted above */
p1 = (char*)b; /* legal because the cast
changes the type */
return 0;
}
// gcc -Wall schwartz2.c -o x.exe
This compiles with the following warnings, but hangs.
C:\MinGW\source> gcc -Wall schwartz2.c -o x.exe
I would hate to my name associated with such abominable code. But
since you misspelled my name I don't have to worry about it.
schwartz2.c: In function `main':
schwartz2.c:17: warning: suggest parentheses around assignment used as
truth val
Be honest. You are just trolling. What other reason do you have for
ignoring the compiler identifying the problems in your code.
ue
schwartz2.c:22: warning: suggest parentheses around assignment used as
truth val
ue
schwartz2.c:33: warning: assignment from incompatible pointer type
schwartz2.c:15: warning: unused variable `c'
C:\MinGW\source>
I usually populate integer arrays by assigning them to the index of a loop
that runs the range. I thought it would be a good thing to avoid the first
32 chars and start with sixty instead, which is zero on my implementation.
ASCII uses 0x30 and EBCDIC uses 0xf0. I once worked with a Hazeltine
display system where '0' was 0x60 but '1' was 0x62 so it could not be
a C system. Could you give us the brand name or the name of the
coding convention that uses 0x3c for '0' as you claim.
??
Think about the difference between p1++ and p2++.
One is legal; the other is not? They vary by one degree of indirection?
The drapes don't match the curtains?
Surely you jest. Both expressions are perfectly legal if the pointer
in question has been assigned a valid non-NULL value.
Maybe you and Bill Cunningham could form a club and tutor each other.
Yes Barry, I changed the equals to less than and now have a program I
understand. Did my complete lack of snipping above appeal to your
sensibilities (rhetorical question, see number 1)?
1) Do not reply to me again.
2) Schwartz means "black".
3) If Bill's a reasonable human being, I would much rather endure his
company as opposed to yours.
4) You're the size of my average bowel movement.
--
George
Today we affirm a new commitment to live out our nation's promise through
civility, courage, compassion and character.
George W. Bush
Picture of the Day http://apod.nasa.gov/apod/
.
- References:
- making bytes out of bits
- From: George
- Re: making bytes out of bits
- From: Barry Schwarz
- Re: making bytes out of bits
- From: George
- Re: making bytes out of bits
- From: Barry Schwarz
- Re: making bytes out of bits
- From: George
- Re: making bytes out of bits
- From: nick_keighley_nospam
- Re: making bytes out of bits
- From: George
- Re: making bytes out of bits
- From: Barry Schwarz
- Re: making bytes out of bits
- From: George
- Re: making bytes out of bits
- From: Barry Schwarz
- making bytes out of bits
- Prev by Date: Re: Retaining the value of the variable across dynamic library
- Next by Date: Re: tree
- Previous by thread: Re: making bytes out of bits
- Next by thread: Re: making bytes out of bits
- Index(es):
Relevant Pages
|