Macro to calculate seconds of a year ( 16 bit processor)

S

Shilpa

Hi
Can anyone guide me by providing me the code ,for the following
requirement:
how to write a macro for a 16 bit processor that returns the
calculated seconds of a year assuming 365 days in a year ?

Thanking you in advance
 
R

Richard Bos

Shilpa said:
Hi
Can anyone guide me by providing me the code ,for the following
requirement:
how to write a macro for a 16 bit processor that returns the
calculated seconds of a year assuming 365 days in a year ?

#define NUMBER_OF_SECONDS_IN_A_SHORT_YEAR 31536000L

HTH; HAND.

Richard
 
B

Barry Schwarz

Hi
Can anyone guide me by providing me the code ,for the following
requirement:
how to write a macro for a 16 bit processor that returns the
calculated seconds of a year assuming 365 days in a year ?

In C, macros do not perform calculations. Nor are they functions so
they don't return anything. They serve only two purposes:

They define macro names whose existence can be tested for by
certain preprocessor directives.

They identify text substitutions that are to be performed by the
preprocessor.

Since the maximum value allowed in a 16 bit variable is 65535 and the
number of seconds in a year is on the order of 31.5 million, maybe you
could rephrase your request so we know what you really want.


Remove del for email
 
D

dcorbit

Shilpa said:
Hi
Can anyone guide me by providing me the code ,for the following
requirement:
how to write a macro for a 16 bit processor that returns the
calculated seconds of a year assuming 365 days in a year ?

Thanking you in advance

There are not 365 days in a year. If you start with a wrong
assumption, you end up with wrong answers.

P.S.
There are 86,400 seconds in a day (ignoring leap seconds)

P.P.S.
If you want the right answer, you can't ignore leap seconds

P.P.P.S.
Leap seconds are pretty rare, I suggest a table lookup.
 
W

Walter Roberson

On 20 Nov 2006 03:44:23 -0800, "Shilpa" <[email protected]>
wrote:
Since the maximum value allowed in a 16 bit variable is 65535 and the
number of seconds in a year is on the order of 31.5 million, maybe you
could rephrase your request so we know what you really want.

On the other hand, a "16 bit processor" is not necessarily
restricted to 16 bit variables -- but it probably would have trouble
if the macro expanded to more than 65535 characters ;-)
 
K

Keith Thompson

There are not 365 days in a year. If you start with a wrong
assumption, you end up with wrong answers.

There are 365 days in *this* year. (The word "year" is ambiguous.)
 
S

Shilpa

Barry said:
In C, macros do not perform calculations. Nor are they functions so
they don't return anything. They serve only two purposes:

They define macro names whose existence can be tested for by
certain preprocessor directives.

They identify text substitutions that are to be performed by the
preprocessor.

Hey u r rite in making me understand what a macro is used for. I do
know macros cannot return values, i think i put my question in a wrong
way
Since the maximum value allowed in a 16 bit variable is 65535 and the
number of seconds in a year is on the order of 31.5 million, maybe you
could rephrase your request so we know what you really want.

What I wanted to ask is how to display such a large value in the 16-bit
variables. I guess we have to use array of integers, but how to proceed
after that.
 
K

Keith Thompson

Shilpa said:
Hey u r rite in making me understand what a macro is used for.
[...]

Please don't use silly abbreviations like 'u' and 'r' here.
What I wanted to ask is how to display such a large value in the 16-bit
variables. I guess we have to use array of integers, but how to proceed
after that.

A 16-bit variable can only hold 65536 distinct values; if it's a
signed integer, it can't hold a value greater than 32767. But why do
you assume you can only use 16-bit variables? Even on a so-called
"16-bit" machine, C requires for at least 32-bit types (64-bit for
C99).
 
S

santosh

Shilpa said:
What I wanted to ask is how to display such a large value in the 16-bit
variables. I guess we have to use array of integers, but how to proceed
after that.

In standard C, the type unsigned long int is atleast 32 bits and so
will be more than sufficient for your purpose.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,999
Messages
2,570,246
Members
46,839
Latest member
MartinaBur

Latest Threads

Top