Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > 2/4 bytes boundary problem

Reply
Thread Tools

2/4 bytes boundary problem

 
 
Rafael Almeida
Guest
Posts: n/a
 
      05-15-2006
On Mon, 15 May 2006 15:16:17 +0100
Flash Gordon <> wrote:

> You've got an error on line 42 of func.
>
> In other words, if you don't show us your code how are we expected to
> know what you have done wrong? Post a small complete compilable
> program that exhibits the problem.
> http://clc-wiki.net/wiki/Intro_to_clc


Why people say that it's an "error on line 42"? Why specifically line
42? I looked for it on c-faq.com and that wiki but there's no entries
for it.
 
Reply With Quote
 
 
 
 
Vladimir Oka
Guest
Posts: n/a
 
      05-15-2006
Rafael Almeida opined:

> On Mon, 15 May 2006 15:16:17 +0100
> Flash Gordon <> wrote:
>
>> You've got an error on line 42 of func.
>>
>> In other words, if you don't show us your code how are we expected
>> to know what you have done wrong? Post a small complete compilable
>> program that exhibits the problem.
>> http://clc-wiki.net/wiki/Intro_to_clc

>
> Why people say that it's an "error on line 42"? Why specifically line
> 42? I looked for it on c-faq.com and that wiki but there's no entries
> for it.


Look up Hitchhikers Guide to the Galaxy, by Douglas Adams. I'd go even
further, and recommend you actually read it (and all the sequels).

42 is the answer to Life, Universe, and Everything. But, what is the
*question*?

--
Time is fluid ... like a river with currents, eddies, backwash.
-- Spock, "The City on the Edge of Forever", stardate 3134.0

<http://clc-wiki.net/wiki/Introduction_to_comp.lang.c>

 
Reply With Quote
 
 
 
 
Andrew Poelstra
Guest
Posts: n/a
 
      05-15-2006
On 2006-05-15, Rafael Almeida <> wrote:
> On Mon, 15 May 2006 15:16:17 +0100
> Flash Gordon <> wrote:
>
>> You've got an error on line 42 of func.
>>
>> In other words, if you don't show us your code how are we expected to
>> know what you have done wrong? Post a small complete compilable
>> program that exhibits the problem.
>> http://clc-wiki.net/wiki/Intro_to_clc

>
> Why people say that it's an "error on line 42"? Why specifically line
> 42? I looked for it on c-faq.com and that wiki but there's no entries
> for it.


42 is a reference to "Hitchhiker's Guide to the Galaxy" and is a very
profound number. Line 42 means that *you didn't post any code* (or not
enough code) and therefore must assume that the code is floating
through space and is part of the very fabric of the universe. And line
42 has a glitch which causes all the problems of the world.

In most cases, unposted code is merely unposted code and nothing else.
But we can hope...

(I starred the only important part of that paragraph)
 
Reply With Quote
 
Default User
Guest
Posts: n/a
 
      05-15-2006
Rafael Almeida wrote:

> On Mon, 15 May 2006 15:16:17 +0100
> Flash Gordon <> wrote:
>
> > You've got an error on line 42 of func.
> >
> > In other words, if you don't show us your code how are we expected
> > to know what you have done wrong? Post a small complete compilable
> > program that exhibits the problem.
> > http://clc-wiki.net/wiki/Intro_to_clc

>
> Why people say that it's an "error on line 42"? Why specifically line
> 42? I looked for it on c-faq.com and that wiki but there's no entries
> for it.



It's the answer to the question, always. Life, the Universe,
everything.

<http://en.wikipedia.org/wiki/The_Ans...erse,_and_Ever
ything>




Brian
 
Reply With Quote
 
Nelu
Guest
Posts: n/a
 
      05-16-2006

Rafael Almeida wrote:
> On Mon, 15 May 2006 15:16:17 +0100
> Flash Gordon <> wrote:
>
> > You've got an error on line 42 of func.
> >
> > In other words, if you don't show us your code how are we expected to
> > know what you have done wrong? Post a small complete compilable
> > program that exhibits the problem.
> > http://clc-wiki.net/wiki/Intro_to_clc

>
> Why people say that it's an "error on line 42"? Why specifically line
> 42? I looked for it on c-faq.com and that wiki but there's no entries
> for it.


It's related to the cosmological constant (between 40 and 50, if it's
really a constant - Hubble diagrams help). The Hitchhiker's Guide...
(book, movie) makes it 42 and sets it as the answer to everything.
There's no theory behind 42 other than "between 40 and 50" so it's like
popping a number from the top of your head without having any idea what
the number is, exactly like finding the error in a piece of code that
you don't have access to.

--
Ioan - Ciprian Tandau
tandau _at_ freeshell _dot_ org (hope it's not too late)
(... and that it still works...)

 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      05-16-2006
Nelu said:

> There's no theory behind 42 other than "between 40 and 50"


Not even that.

DNA was astounded to learn that astronomers are finding a use for 42. When
he chose it, it was for no other reason than that it was the sort of number
you would be happy to take home and introduce to your parents.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
 
Reply With Quote
 
Thomas.Chang
Guest
Posts: n/a
 
      05-16-2006
My bad for not stating that my program is just a little piece of an
embedded system, a router.
I know that a lot of factors may cause the crash. But it does work well
after I swapped the position of "c" and "d".
I heard that problems occur when you try to fetch a member which
locates across boundaries, but I don't know what the problem can be,
crash? Maybe...
btw, the CPU is IXP425 for my router. I know that the "packed" option
can prohibit padding, which is dangerous for packets constructing or
parsing. But my code is runtime data structure, which can be paded at
one's wish.
Then why the CPU didn't pad it? Is it sleeping?... Oh, god!

Duncan Muirhead wrote:
> On Mon, 15 May 2006 06:58:15 -0700, Thomas.Chang wrote:
>
> > Hi,
> >
> > As we know, the compiler will pad structure to make it align on 4
> > byte boundaries.
> > I got a structure like this.
> > typedef struct{
> > uint8 a;
> > uint8 b;
> > uint8 c;
> > uint16 d;
> > ...
> > }s;
> > s s1;
> > ... func(..., &s1.d, ...){...}
> > But I always got crash when calling func(). I interchanged the
> > position of "c" and "d", anything went ok.
> > As the compiler will pad it right. Why I cannot fetch the address of
> > "d"?
> > Although the position of "c" and "d" is swapped, "d" is still not on
> > 4 byte boundary. But it works well, why?
> >
> > Thomas

>
> Hard to say without more details. For example this:
> #include <stdio.h>
> typedef struct
> { char a;
> char b;
> char c;
> short int d;
> int e;
> } s;
> static void hmm( s* s, short int* d)
> { printf( "hmm %d -> %d\n", (char*)d-(char*)s, *d);
> }
> int main( int argc, char** argv)
> {
> s s1 = { 1, 2, 3, 444, 5};
> hmm( &s1, &s1.d);
> return 0;
> }
> compiled with "gcc -Wall -pedantic -ansi -o pad pad.c" (gcc 3.4.5) doesn't
> show any problems -- abd prints hmm "4 -> 444" as one would expect.
>
> Duncan


 
Reply With Quote
 
Thomas.Chang
Guest
Posts: n/a
 
      05-16-2006
yes, the u stands for unsigned.
I just want to emphasize the length of storage for each member.

Andrew Poelstra wrote:
> On 2006-05-15, Andrew Poelstra <> wrote:
> > On 2006-05-15, Robert Gamble <> wrote:
> >> Andrew Poelstra wrote:
> >>> On 2006-05-15, Thomas.Chang <> wrote:
> >>> > Hi,
> >>> >
> >>> > As we know, the compiler will pad structure to make it align on 4
> >>> > byte boundaries.
> >>> No, that's not guaranteed at all. Where did you hear that?
> >>>
> >>> > I got a structure like this.
> >>> > typedef struct{
> >>> > uint8 a;
> >>> > uint8 b;
> >>> > uint8 c;
> >>> Why not just use chars?
> >>
> >> unsigned char would be the correct recommendation in this case.
> >>

> > Is a uint8 unsigned by default? I honestly don't know.
> >

> Wait... that's what the u is for, isn't it? I've really got
> to go to bed.


 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      05-16-2006


Nelu wrote On 05/15/06 23:40,:
> Rafael Almeida wrote:
>
>>On Mon, 15 May 2006 15:16:17 +0100
>>Flash Gordon <> wrote:
>>
>>
>>>You've got an error on line 42 of func.
>>>
>>>In other words, if you don't show us your code how are we expected to
>>>know what you have done wrong? Post a small complete compilable
>>>program that exhibits the problem.
>>>http://clc-wiki.net/wiki/Intro_to_clc

>>
>>Why people say that it's an "error on line 42"? Why specifically line
>>42? I looked for it on c-faq.com and that wiki but there's no entries
>>for it.

>
>
> It's related to the cosmological constant (between 40 and 50, if it's
> really a constant - Hubble diagrams help). The Hitchhiker's Guide...
> (book, movie) makes it 42 and sets it as the answer to everything.
> There's no theory behind 42 [...]


<off-topic>

I beg to differ: There *is* a theory behind 42. It's
not only the Ultimate Answer to the Question of Life, the
Universe, and Everything, but it's also the answer to the
specific question

What do you get if you multiply six by nine?

.... which I think should be read with an emphasis on the
second "you."

</off-topic>

--


 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      05-19-2006
Eric Sosman <> writes:
[...]
> <off-topic>
>
> I beg to differ: There *is* a theory behind 42. It's
> not only the Ultimate Answer to the Question of Life, the
> Universe, and Everything, but it's also the answer to the
> specific question
>
> What do you get if you multiply six by nine?
>
> ... which I think should be read with an emphasis on the
> second "you."
>
> </off-topic>


#include <stdio.h>

#define SIX 1+5
#define NINE 8+1

int main(void)
{
printf("%d * %d = %d\n", SIX, NINE, SIX * NINE);
return 0;
}

--
Keith Thompson (The_Other_Keith) kst- <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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Ratio of Bytes Delayed to Bytes Sent netproj Cisco 0 12-21-2005 08:08 PM
4-bytes or 8-bytes alignment? mrby C Programming 8 11-02-2004 08:45 PM
Private Bytes vs. # Bytes in all Heaps in Perfmon Jason Collins ASP .Net 3 02-18-2004 03:59 PM
Re: receiving Bytes and sending Bytes Ieuan Adams Computer Support 0 07-24-2003 07:46 PM
Re: receiving Bytes and sending Bytes The Old Sourdough Computer Support 0 07-23-2003 01:23 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57