Re: sizeof(DateType) == 2 ?

2008-05-28 Thread Jamie Macleod
Ahhh, thank you.  I knew I was missing something obvious.  Actually, I have
a book, it's just not great on explaining structures.  You wouldn't know it
from my question, but I know C, I just haven't used it for 10 years, so I'm
very rusty.

Jamie

Richard Burmeister [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]

 From: Jamie Macleod [EMAIL PROTECTED]
 Subject: sizeof(DateType) == 2 ?

  Can someone explain why sizeof(DateType) gives me 2?  DateType is a
  structure declared as 3 UInt16 values, and of course if I do a
  (sizeof(UInt16) * 3) I get 6.  Shouldn't I be getting 6 for DateType?

 DateType is not a structure with 3 UInt16s.  It is a single UInt16 used as
a
 bit field (16 bits, 2 bytes).

 typedef struct {
   UInt16 year :7;
   UInt16 month :4;
   UInt16 day :5;
 } DateType;

 7 bits are used for the year, 4 bits for the month, and 5 bits for the
day.

 You might want to pick up a book on C.









-- 
For information on using the ACCESS Developer Forums, or to unsubscribe, please 
see http://www.access-company.com/developers/forums/


Re: sizeof(DateType) == 2 ?

2008-05-28 Thread Garth Watkins
This is because all the elements in DateType are bitfields of a Word. In C
you can actually divide one the integral data types into various fields in a
structure. So in the DateType you have:
typedef struct {
 Word year  :7;   // years since 1904 (MAC format)
 Word month :4;
 Word day   :5;
} DateType;
The whole struct consists only of one Word, and the year member takes up
7bits, month 4 bits and day 5 bits, for a total of 16 bits, hence 2 bytes.

Garth Watkins


- Original Message -
From: Jamie Macleod [EMAIL PROTECTED]
Newsgroups: palm-dev-forum
To: Palm Developer Forum palm-dev-forum@news.palmos.com
Sent: Sunday, November 05, 2000 4:50 PM
Subject: sizeof(DateType) == 2 ?


 Can someone explain why sizeof(DateType) gives me 2?  DateType is a
 structure declared as 3 UInt16 values, and of course if I do a
 (sizeof(UInt16) * 3) I get 6.  Shouldn't I be getting 6 for DateType?

 Jamie



 --
 For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/tech/support/forums/




-- 
For information on using the ACCESS Developer Forums, or to unsubscribe, please 
see http://www.access-company.com/developers/forums/


sizeof(DateType) == 2 ?

2008-05-28 Thread Jamie Macleod
Can someone explain why sizeof(DateType) gives me 2?  DateType is a
structure declared as 3 UInt16 values, and of course if I do a
(sizeof(UInt16) * 3) I get 6.  Shouldn't I be getting 6 for DateType?

Jamie





-- 
For information on using the ACCESS Developer Forums, or to unsubscribe, please 
see http://www.access-company.com/developers/forums/


sizeof returns incorrect value

2005-03-17 Thread mguo
I am using CodeWarrior8.3. I have a following structure, when i use sizeof on 
this structure, it returns 12, but i expect 8.
Does anybody know why?  Thanks, -mguo

typedef struct
{
  union
  {
 UInt32 u1;
 UInt32 u2;
  };

  union
  {
 UInt16 u3;
 UInt16 u4;
  };

  union
  {
 UInt16 u5;
 UInt16 u6;
  };
} UserType;
-- 
For information on using the Palm Developer Forums, or to unsubscribe, please 
see http://www.palmos.com/dev/support/forums/


Re: sizeof returns incorrect value

2005-03-17 Thread Wade Guthrie
mguo wrote:
I am using CodeWarrior8.3. I have a following structure, when i use sizeof on 
this structure, it returns 12, but i expect 8.
Does anybody know why?  Thanks, -mguo
typedef struct
{
 union
 {
UInt32 u1;
UInt32 u2;
 };
 union
 {
UInt16 u3;
UInt16 u4;
 };
 union
 {
UInt16 u5;
UInt16 u6;
 };
} UserType;
 

The compiler could be adding 2 bytes of padding after each of the u3/u4 
and u5/u6 unions.  That would be a little silly since the UInt16 
probably doesn't have 32 bit alignment restrictions but it would 
describe the reason for the size.  It would be even sillier for the 
compiler to be adding 4 bytes of padding after the u5/u6 union but, I 
guess, it would be possible.

Is there a compiler flag to describe structure member padding?
--
Wade
[EMAIL PROTECTED]

--
For information on using the Palm Developer Forums, or to unsubscribe, please 
see http://www.palmos.com/dev/support/forums/


Re: sizeof returns incorrect value

2005-03-17 Thread Ingbert Grimpe
On Thu, 17 Mar 2005 18:23:19 -, mguo [EMAIL PROTECTED] wrote:
I am using CodeWarrior8.3. I have a following structure, when i use  
sizeof on this structure, it returns 12, but i expect 8.
Just because you 'expect' something, it doesn't need to be correct ;)
Does anybody know why?  Thanks, -mguo
Alignment.
Probably you have sruct-alignment in the project panel set to 68k-4Byte.  
You might try 68k instead.
There's also a pragma to set the alignment: #pragma options align=  
alignment
(search for 'align' in the online manual to get the allowed values)

(I use CW 9.x but it should apply to 8.x too)
--
For information on using the Palm Developer Forums, or to unsubscribe, please 
see http://www.palmos.com/dev/support/forums/


Re: sizeof returns incorrect value

2005-03-17 Thread mguo
Thanks for quick response, Wade and Ingbert!
actually, alignment is also what i thought. 
i double-checked my target setting, which is 68k, not 68k-4byte. so it 
should use 2-byte alignment.
Even if 68k-4byte, compiler shouldn't pad 2 extra bytes after union2 and 
union3, because the total size of union2 + union3 is already 4 bytes.
I can try to use #pragma to force 2-byte alignment.

Thanks again
-mguo
-- 
For information on using the Palm Developer Forums, or to unsubscribe, please 
see http://www.palmos.com/dev/support/forums/


Re: sizeof returns incorrect value

2005-03-17 Thread mguo
i use #pragma options align=mac68k to force 2-byte alignment, it still does 
the same thing. It might be a bug in compiler, I guess.

-mguo
-- 
For information on using the Palm Developer Forums, or to unsubscribe, please 
see http://www.palmos.com/dev/support/forums/


Re: sizeof returns incorrect value

2005-03-17 Thread Jan Slodicka
Maybe...

In any case the aligment speculations are wrong.
I tried CW9.3 and MC VC++ - both showing 8 bytes.

Best regards,
Jan Slodicka

- Original Message - 
From: mguo [EMAIL PROTECTED]
To: Palm Developer Forum palm-dev-forum@news.palmos.com
Sent: Thursday, March 17, 2005 8:07 PM
Subject: Re: sizeof returns incorrect value


 i use #pragma options align=mac68k to force 2-byte alignment, it still
does the same thing. It might be a bug in compiler, I guess.

 -mguo
 -- 
 For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please 
see http://www.palmos.com/dev/support/forums/


Re: sizeof returns incorrect value

2005-03-17 Thread Ingbert Grimpe
On Thu, 17 Mar 2005 19:07:49 -, mguo [EMAIL PROTECTED] wrote:
i use #pragma options align=mac68k to force 2-byte alignment, it still
Have you tried 'packed' for this structure?
--
For information on using the Palm Developer Forums, or to unsubscribe, please 
see http://www.palmos.com/dev/support/forums/


sizeof enumerated type

2004-12-27 Thread Sinisa Marovic (AC/EDD)
Hi,

  I have a small problem using prc tools 2.3. I'm using EvtGetEvent function
within a PNOlet, and I'm using standard (sdk-5) EventType definition in Event.h.
The problem is that none of the events seems to be recognized in the loop. When
I printed a value of the eType field, I could immediately see what the problem
is: the value is 4 bytes long, when using m68k code, it uses 2 bytes. I defined
my own EventType1, which is the same as EventType, except that eType is defined
as UInt16, and that worked. I guess casting would work, although I haven't tried
that (something like (UInt16)event.eType).

My questions are: why is this happening? Is there a way to 'tell' the compiler
to use 2 bytes for enum instead? God know on how many places this could occure.

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please 
see http://www.palmos.com/dev/support/forums/


OS 5.0 5.3 Headers Give Diff Results for sizeof(MyStruct)

2004-01-15 Thread Mike McCollister
Here is a structure that I have been using:

typedef struct MyColorTableType
{
   Int16 numEntries;
   UInt8 fill[2];
   RGBColorType entry[UILastColorTableEntry];
} MyStruct;

When I compile using the OS 5.0 header files, I get sizeof(MyStruct) = 124. 
However, when I compile using the OS 5.3 header files, I get sizeof(MyStruct) =
128.  The OS 5.0 result is the corrent one.   Any ideas on how to get this to
work on OS 5.3?

Thanks,

Mike

__
Do you Yahoo!?
Yahoo! Hotjobs: Enter the Signing Bonus Sweepstakes
http://hotjobs.sweepstakes.yahoo.com/signingbonus

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/


Re: OS 5.0 5.3 Headers Give Diff Results for sizeof(MyStruct)

2004-01-15 Thread Mike McCollister
Found the problem.  It turns out that in the OS 5.0 header files
UILastColorTableEntry is 30 and in the OS 5.3 header files
UILastColorTableEntry is 31.

Mike

--- Mike McCollister [EMAIL PROTECTED] wrote:
 Here is a structure that I have been using:
 
 typedef struct MyColorTableType
 {
Int16 numEntries;
UInt8 fill[2];
RGBColorType entry[UILastColorTableEntry];
 } MyStruct;
 
 When I compile using the OS 5.0 header files, I get sizeof(MyStruct) = 124. 
 However, when I compile using the OS 5.3 header files, I get sizeof(MyStruct)
 =
 128.  The OS 5.0 result is the corrent one.   Any ideas on how to get this to
 work on OS 5.3?
 
 Thanks,
 
 Mike
 
 __
 Do you Yahoo!?
 Yahoo! Hotjobs: Enter the Signing Bonus Sweepstakes
 http://hotjobs.sweepstakes.yahoo.com/signingbonus
 
 -- 
 For information on using the Palm Developer Forums, or to unsubscribe, please
 see http://www.palmos.com/dev/support/forums/


__
Do you Yahoo!?
Yahoo! Hotjobs: Enter the Signing Bonus Sweepstakes
http://hotjobs.sweepstakes.yahoo.com/signingbonus

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/


Re: CodeWarrior: #IF SIZEOF(struct) == X ?

2003-12-20 Thread Ben Combee
At 05:02 PM 12/19/2003, Peter Easton wrote:
Hi,

I'm looking to receive some kind of compile-time notification if a structure
size isn't what I'd expect it to be.  Something like:
#IF SIZEOF(MyStructType) != 100 DISPLAY Oops, there's problem
You can't do this with the preprocessor since it doesn't have info on 
types.  However, you can do this with the compiler by writing something like:

typedef int TEST_MYSTRUCT_SIZE[sizeof(MyStructType)] == 100];

If the expression inside the array bounds is false, it will evaluate to 0 
which is an invalid array size.  Otherwise, it will be 1, and you'll just 
be left with an unused typedef.

--
Ben Combee [EMAIL PROTECTED]
CodeWarrior for Palm OS technical lead
Palm OS programming help @ www.palmoswerks.com 

--
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/


CodeWarrior: #IF SIZEOF(struct) == X ?

2003-12-19 Thread Peter Easton
Hi,

I'm looking to receive some kind of compile-time notification if a structure
size isn't what I'd expect it to be.  Something like:

#IF SIZEOF(MyStructType) != 100 DISPLAY Oops, there's problem

Thanks,

Peter



-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/


Re: CodeWarrior: #IF SIZEOF(struct) == X ?

2003-12-19 Thread John Marshall
Peter Easton [EMAIL PROTECTED] wrote:
 I'm looking to receive some kind of compile-time notification if a structure
 size isn't what I'd expect it to be.  Something like:
 
 #IF SIZEOF(MyStructType) != 100 DISPLAY Oops, there's problem

Sadly the sizeof operator is not available in the preprocessor (see also
question 10.13 of the C FAQ).

The usual trick is to try to cause a compilation error by doing something
like
char foo[sizeof (MyStructType) == 100];

except that that's not quite good enough (char foo[0] is a valid
declaration e.g. with GCC in the absence of -pedantic), so the following
is better:

char foo[(sizeof (MyStructType) == 100)? 1 : -1];

That was cribbed from the Poser source code -- Keith discovered that
char foo[0] had become valid at some stage and improved the macro he
was using for the thing you want to do.  Look at COMPILE_TIME_ASSERT in
EmCommon.h for details.

John

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/


Re: sizeof

2003-08-14 Thread Engi
On Saturday, August 09, 2003 9:35 PM [GMT+1=CET],
Carsten [EMAIL PROTECTED] wrote:

 most (some.. ;) compliers have the ability to define the struct
 alignment.

Is it the case with CW ?

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/


Re: sizeof

2003-08-14 Thread Jeremy Neal Kelly
rguevara [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]

 Because the Char allocate one more bit for '\0'

Sorry, but this is definitely *not* correct; see Ben Combee's earlier post
for the correct answer.


Jeremy Neal Kelly
Software Engineer
Peapod




-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/


Re: sizeof

2003-08-14 Thread Ben Combee
At 10:00 AM 8/8/2003, Engi wrote:
Hi,

Is someone could explain me this :

sizeof(DateType) = 2
sizeof(Char) = 1
typedef struct
{
 DateType date;
 Char  value;
}
stACTIONS;
sizeof(stACTIONS) = 4  ???

Why sizeof(stACTIONS) is not 3 ?
Because stActions has to be aligned on a two-byte boundary if used in an 
array.  To do this, the compiler adds a byte of padding after value so 
the next item will be properly aligned.

--
Ben Combee [EMAIL PROTECTED]
CodeWarrior for Palm OS technical lead
Palm OS programming help @ www.palmoswerks.com 

--
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/


Re: sizeof

2003-08-09 Thread Carsten

most (some.. ;) compliers have the ability to define the struct
alignment.




-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/


Re: sizeof

2003-08-09 Thread Ben Combee
At 02:43 PM 8/9/2003, Engi wrote:
On Saturday, August 09, 2003 9:35 PM [GMT+1=CET],
Carsten [EMAIL PROTECTED] wrote:
 most (some.. ;) compliers have the ability to define the struct
 alignment.
Is it the case with CW ?
Have you tried reading the compiler manual (hint - search for packed).

--
Ben Combee [EMAIL PROTECTED]
CodeWarrior for Palm OS technical lead
Palm OS programming help @ www.palmoswerks.com 

--
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/


sizeof

2003-08-08 Thread Engi
Hi,

Is someone could explain me this :

sizeof(DateType) = 2
sizeof(Char) = 1

typedef struct
{
 DateType date;
 Char  value;
}
stACTIONS;

sizeof(stACTIONS) = 4  ???

Why sizeof(stACTIONS) is not 3 ?


Engi

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/


Re: GCC sizeof bug?

2002-10-13 Thread Michael Harrison

This is thoroughly frustrating.  I just tried both methods that worked
for you, and go ahead and guess, they worked fine for me.

Evidently there was some subtle difference that I missed the first
time.


On Wed, 9 Oct 2002 13:05:17 +0200, John Marshall [EMAIL PROTECTED]
wrote:


On Thu, Oct 03, 2002 at 05:43:38AM -0500, Michael Harrison wrote:
 TraceOutput( TL( appErrorClass, re-allocated %hu bytes of record
 memory, gNumRecordsAllocated * sizeof(UInt16) ) );

The sizeof operator returns a size_t, which, on Palm OS with both GCC
and CodeWarrior, is the same size as a long.  So your code is wrong: you
should be using %lu instead.

Rather than trying to remember how big a size_t is, when passing one
to a varargs function like printf it's a common idiom to cast it to
something known, as you have done:

 TraceOutput( TL( appErrorClass, re-allocated %hu bytes of record
 memory, UInt16(gNumRecordsAllocated * sizeof(UInt16)) ) );

or to use an explicit temporary:

 UInt16 BytesAlloc = gNumRecordsAllocated * sizeof(UInt16);
 TraceOutput( TL( appErrorClass, re-allocated %hu bytes of record
 memory, BytesAlloc ) );

Both of these produced the appropriately sized argument for %hu for me.
I was unable to reproduce the problem you say you had with the former.

John



  Michael S. Harrison
  michaelh.dragonseye@com
  (reverse the dot and at to send email)

* The opinions expressed here are those of my iguana
* and I never know what he's going to say next.

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/



Re: GCC sizeof bug?

2002-10-09 Thread John Marshall

On Thu, Oct 03, 2002 at 05:43:38AM -0500, Michael Harrison wrote:
 TraceOutput( TL( appErrorClass, re-allocated %hu bytes of record
 memory, gNumRecordsAllocated * sizeof(UInt16) ) );

The sizeof operator returns a size_t, which, on Palm OS with both GCC
and CodeWarrior, is the same size as a long.  So your code is wrong: you
should be using %lu instead.

Rather than trying to remember how big a size_t is, when passing one
to a varargs function like printf it's a common idiom to cast it to
something known, as you have done:

 TraceOutput( TL( appErrorClass, re-allocated %hu bytes of record
 memory, UInt16(gNumRecordsAllocated * sizeof(UInt16)) ) );

or to use an explicit temporary:

 UInt16 BytesAlloc = gNumRecordsAllocated * sizeof(UInt16);
 TraceOutput( TL( appErrorClass, re-allocated %hu bytes of record
 memory, BytesAlloc ) );

Both of these produced the appropriately sized argument for %hu for me.
I was unable to reproduce the problem you say you had with the former.

John

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/



struct size error(sizeof Error?)

2001-07-30 Thread J.J

Hi!


I'm define my source below that 


int size;

typedef struct test
{
chardata1[10];
chardata2[1];
}my_test;

size = sizeof(my_test);


I guess the value of size is 11 but, size value is 12


What's wrong???

I'm using CodeWarrior 7.
Please Help


¢¸§~Šæjبž‰î²)ඏjYƒz÷¥¢—«ŠîšÊ+¶‹§²æìr¸›z™^jǬyèm¶ŸÿÃ
)jY¨±Êýׯþל‡û.¦š+·÷è®é¬


RE: struct size error(sizeof Error?)

2001-07-30 Thread Richard Anderson

Nothings wrong, the compiler will be padding the structure out to ensure
that it is word aligned. On 68K machines data must be word aligned (this
does not matter for chars though). This structure does not actually need to
word aligned, but if you had one with int data1[10] and then char data2[1],
if you were to have an array of these, the structures with the odd indexs
would cause bus errors when you read the words as they are not aligned on a
even address. The rule is simple : Datatypes bigger than 1 char, must start
on a even address.

Rik

 -Original Message-
 From: J.J [SMTP:[EMAIL PROTECTED]]
 Sent: 30 July 2001 09:14
 To:   Palm Developer Forum
 Subject:  struct size error(sizeof Error?)
 
 Hi!
 
 
 I'm define my source below that 
 
 
 int size;
 
 typedef struct test
 {
   chardata1[10];
   chardata2[1];
 }my_test;
 
 size = sizeof(my_test);
 
 
 I guess the value of size is 11 but, size value is 12
 
 
 What's wrong???
 
 I'm using CodeWarrior 7.
 Please Help
 
 
 £¿£¿+£¿b£¿'ºÈ£¿£¿=£¿
 ëÞ£¿^£¿+£¿(®Ú.£¿£¿Êâm£¿y?±ç¡¶£¿?0¥©f¢Ç(£¿^¿û^r캣¿®ßߢ»¦

--
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/



Re: struct size error(sizeof Error?)

2001-07-30 Thread Gavin Maxwell

It's called padding and it's added by the compiler to bring everything up 
to even byte boundaries...

Cheers,
Gavin.

Hi!


I'm define my source below that


int size;

typedef struct test
{
 chardata1[10];
 chardata2[1];
}my_test;

size = sizeof(my_test);


I guess the value of size is 11 but, size value is 12


What's wrong???

I'm using CodeWarrior 7.
Please Help


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/



Re: sizeof(DateType) == 2 ?

2000-11-11 Thread Ricardo Contin

We will have a new year BUG ? in 2032 ??

For Palm and MAC ???


- Original Message -

From: "Garth Watkins" [EMAIL PROTECTED]
To: "Palm Developer Forum" [EMAIL PROTECTED]
Sent: Sunday, November 05, 2000 1:27 PM
Subject: Re: sizeof(DateType) == 2 ?


 This is because all the elements in DateType are bitfields of a Word. In C
 you can actually divide one the integral data types into various fields in
a
 structure. So in the DateType you have:
 typedef struct {
  Word year  :7;   // years since 1904 (MAC format)
  Word month :4;
  Word day   :5;
 } DateType;
 The whole struct consists only of one Word, and the year member takes up
 7bits, month 4 bits and day 5 bits, for a total of 16 bits, hence 2 bytes.

 Garth Watkins


 - Original Message -
 From: "Jamie Macleod" [EMAIL PROTECTED]
 Newsgroups: palm-dev-forum
 To: "Palm Developer Forum" [EMAIL PROTECTED]
 Sent: Sunday, November 05, 2000 4:50 PM
 Subject: sizeof(DateType) == 2 ?


  Can someone explain why sizeof(DateType) gives me 2?  DateType is a
  structure declared as 3 UInt16 values, and of course if I do a
  (sizeof(UInt16) * 3) I get 6.  Shouldn't I be getting 6 for DateType?
 
  Jamie
 
 
 
  --
  For information on using the Palm Developer Forums, or to unsubscribe,
 please see http://www.palmos.com/dev/tech/support/forums/
 


 --
 For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/tech/support/forums/


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/



In the year 2032 (was: sizeof(DateType) == 2 ?)

2000-11-11 Thread Richard Burmeister

From: "Ricardo Contin" [EMAIL PROTECTED]
Subject: Re: sizeof(DateType) == 2 ?

 We will have a new year BUG ? in 2032 ??
 For Palm and MAC ???

IF you think either OS will exist in its current form in 2032, then the
answer is yes :).  (Of course, in the 60's nobody thought we'd still be
running all those old COBOL programs this year.)



-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/



RE: In the year 2032 (was: sizeof(DateType) == 2 ?)

2000-11-11 Thread Scott Johnson (Bellevue)

In 2032... Americans will still be arguing over who really won the 2000
election.  :-)

 From: Richard Burmeister [mailto:[EMAIL PROTECTED]]
 IF you think either OS will exist in its current form in 2032,
 then the answer is yes :).  (Of course, in the 60's nobody thought
 we'd still be running all those old COBOL programs this year.)

But problems can occur earlier.  Consider a Palm app that prints an
amortization table for a 30-year mortgage.  Today that would already go out
to about 2030.  So even today, someone writing such a program would best
avoid DateType for representing the dates.

-slj-


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/



sizeof(DateType) == 2 ?

2000-11-05 Thread Jamie Macleod

Can someone explain why sizeof(DateType) gives me 2?  DateType is a
structure declared as 3 UInt16 values, and of course if I do a
(sizeof(UInt16) * 3) I get 6.  Shouldn't I be getting 6 for DateType?

Jamie



-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/



Re: sizeof(DateType) == 2 ?

2000-11-05 Thread Garth Watkins

This is because all the elements in DateType are bitfields of a Word. In C
you can actually divide one the integral data types into various fields in a
structure. So in the DateType you have:
typedef struct {
 Word year  :7;   // years since 1904 (MAC format)
 Word month :4;
 Word day   :5;
} DateType;
The whole struct consists only of one Word, and the year member takes up
7bits, month 4 bits and day 5 bits, for a total of 16 bits, hence 2 bytes.

Garth Watkins


- Original Message -
From: "Jamie Macleod" [EMAIL PROTECTED]
Newsgroups: palm-dev-forum
To: "Palm Developer Forum" [EMAIL PROTECTED]
Sent: Sunday, November 05, 2000 4:50 PM
Subject: sizeof(DateType) == 2 ?


 Can someone explain why sizeof(DateType) gives me 2?  DateType is a
 structure declared as 3 UInt16 values, and of course if I do a
 (sizeof(UInt16) * 3) I get 6.  Shouldn't I be getting 6 for DateType?

 Jamie



 --
 For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/tech/support/forums/



-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/



Re: sizeof(DateType) == 2 ?

2000-11-05 Thread Jamie Macleod

Ahhh, thank you.  I knew I was missing something obvious.  Actually, I have
a book, it's just not great on explaining structures.  You wouldn't know it
from my question, but I know C, I just haven't used it for 10 years, so I'm
very rusty.

Jamie

"Richard Burmeister" [EMAIL PROTECTED] wrote in message
news:29167@palm-dev-forum...

 From: "Jamie Macleod" [EMAIL PROTECTED]
 Subject: sizeof(DateType) == 2 ?

  Can someone explain why sizeof(DateType) gives me 2?  DateType is a
  structure declared as 3 UInt16 values, and of course if I do a
  (sizeof(UInt16) * 3) I get 6.  Shouldn't I be getting 6 for DateType?

 DateType is not a structure with 3 UInt16s.  It is a single UInt16 used as
a
 bit field (16 bits, 2 bytes).

 typedef struct {
   UInt16 year :7;
   UInt16 month :4;
   UInt16 day :5;
 } DateType;

 7 bits are used for the year, 4 bits for the month, and 5 bits for the
day.

 You might want to pick up a book on C.







-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/



Re: sizeof(DateType) == 2 ?

2000-11-05 Thread Richard Burmeister

From: "Jamie Macleod" [EMAIL PROTECTED]
 Ahhh, thank you.  I knew I was missing something obvious.  Actually, I
have
 a book, it's just not great on explaining structures.  You wouldn't know
it
 from my question, but I know C, I just haven't used it for 10 years, so
I'm
 very rusty.

No problem asking!  I use 4 or 5 languages simultaneously, so I frequently
get confused about the syntax myself.



-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/