In Time.h there is a structure defined for time settings. I'm building an embedded system that has a Real Time Clock but it's not PC compatible.
My question is:
I don't some elements of the structure such as day of the week or day of the year, but I do know year,month,date,hour,min,sec. Does the language support filling in the missing elements. And is there a consistency check for that time structure.
1) "The language" has nothing particular to do with this. Which is just as well, since you forgot to mention what the language _is_.
2) is part of the Standard C runtime library, and therefore its behaviour is defined primarily by the C Standard, and secondarily by your compiler toolchain's maker (which you forgot to specify, too). Did you consult your documentation? What did it say?
3) That your system is not a PC is irrelevant. The only thing that matters is whether your C platform is a "hosted environment", at least as far as is concerned, or not.
--
Hans-Bernhard Broeker (broeker@physik.rwth-aachen.de)
Even if all the snow were burnt, ashes would remain.
Hans-Bernard was being helpful. He pointed out that you hadn't told us:
Which language * Which platform * Which toolchain
Without which only general advice can be given.
On many embedded systems you have to provide the implementation of "standard" library routines either through hooks provided by the compiler/toolchain author or directly as a complete routine. Since the embedded system is under your control you might choose to:
Completely ignore the elements in which you are not interested * Provide fixed values for those uninteresting elements
It does depend though whether you are relying on thrid-party source for some time related functions.
OK. The answers to your original questions are: No, and No. Normally, I would include an explaination, but I fear you would consider it "just more babble".
- You have some hardware (micro, memory, RTC) of unknown origin - You have a tool chain of unknown brand and library support - You want to provide standard time functions
What you haven't provided is - which standard? - what functions do you wish to provide? - what support already exists?
Assuming that the answers to above questions are ANSI standard, all and none respectively, the first thing you need is a reference for the C standard library. Then you could consider writing the functions yourself or porting newlib or buying a library.
What are you trying to accomplish? Familiarizing yourself with library implementation? Determine how long your board has been on? Provide a yet another blinking clock for people to set? Port a piece of code that makes use of the time routines? Provide support for others?
All of these may have different answers and they will change depending on what support already exists.
I suspect what you need is to start with something like "The Standard C Library" by Plauger
Of course, this is completely useless advice, because getdate, struct tm and friends are all part of a bigger picture. There have been and continue to be variations on that picture. The advice above is applicable to a working posix conformant system, which you don't, by definition, have. Others seem to have wanted to help you to make (part of) one or find out which part you have in order to solve your problem, instead of just telling you how it should work.
ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here.
All logos and trade names are the property of their respective owners.