• C

y2k conformance in C

How do I ensure that my programs are Y2K compliant while writing programs in C?
LVL 1
duraiskAsked:
Who is Participating?
 
alexoConnect With a Mentor Commented:
1. Store full year in dates (1998 and not just 98).
2. Correctly calculate leap years (divides by 4 but not by 100 unless divides by 400)
3. Familiarize yourself with the time_t, clock_t and struct tm data types and the functions that use them (TIME.H header).
4. Make sure all the external functions you use (C runtime, OS APIs, third party libraries) abide by the same rules.

BTW, there is a Y2K area specifically for these questions...
0
 
duraiskAuthor Commented:
Ok that is fine for my module.but how if a parameter is passed by ref. to that ?
0
 
thresher_sharkCommented:
You could also, of course, set the date on your computer to Jan 2000 and see if the program still works fine :-)
0
Managing Security Policy in a Changing Environment

The enterprise network environment is evolving rapidly as companies extend their physical data centers to embrace cloud computing and software-defined networking. This new reality means that the challenge of managing the security policy is much more dynamic and complex.

 
alexoCommented:
>> but how if a parameter is passed by ref. to that ?
I don't follow, please elaborate.
0
 
alexoCommented:
Hello?
0
 
thresher_sharkCommented:
duraisk may be accessing EE from work in which case he won't be using it for awhile (probably).  Of course it could also be a post-a-question-get-an-answer-and-then-forget-about-it situation
0
 
alexoCommented:
T_S, you're so encouraging...
0
 
duraiskAuthor Commented:
sorry i was little bit busy with the work. so i could not reply
I am in a project which involves writing code in C/C++. we were told to ensure that our programs are y2k conformant.In C i cannot declare variables  as "date" asin other languages. and also if short date values from other modules are passed to my modules how do i ensure that it is made compliant?. While testing, the whole product as such, how do go about testing?

0
 
duraiskAuthor Commented:
Hi T_S
u r partly right and partly wrong
OK
0
 
alexoCommented:
>> In C i cannot declare variables  as "date" as in other languages.
Incorrect.  Although they're part of the standard C library and not the language per se, there are time/date types (I mentioned time_t, clock_t and struct tm in my answer).  As long as you use them you are OK.  If you do your own time/date handling ensure 4 digits for year values and proper leap year handling.

>> if short date values from other modules are passed to my modules how do i ensure that it is made compliant?
Technically you cannot handle all cases.  If an external module passes you a year value of '84' while both 1984 and 2084 are valid in that context, you cannot distinguish between them.

There are certain cases where you can wing it.  If the legal year range in your app starts from, say, 1970 and you only get two digits, add 1900 if the year is greater or equal to 70 and 2000 otherwise.

>> how do go about testing?
Feed your app dates in the 1999-2099 year range and see if it breaks or reports incorrect results.  Set your computer clock to various dates in the above range and repeat the test.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.