-2

I have a file in this massive project I'm working on called timeKeeper.h (and .c)

--------------EDIT---------------FIXED THE BOOL THING STILL BROKEN THOUGH--------------

#ifndef TIMEKEEPER_H_
#define TIMEKEEPER_H_

#include <time.h>
#include <stdbool.h>

bool isAfter(time_t time);
void setTime(char seconds, char minutes, char hours, char day,
        char month, char year);
    void tickSeconds(void);
time_t getCurrentTime(void);
time_t createTime(char seconds, char minutes, char hours, char day,
        char month, char year);
void startTime(void);
time_t addSeconds(int seconds, time_t time);
long timeRemaining(time_t time);
void rtc_set(char seconds, char minutes, char hours, char days, char months,
    char year);
 #endif

When I attempt to Build my project, there are a bunch of errors in this file (and any file that is using time.h). Here's some of the errors in timeKeeper.h:

expected ')' before 'time'        Line 6
expected '"', ',', ';','asm', or '__attribute__' before 'getCurrentTime'    Line 10

I suspect that timeKeeper doesn't know what a time_t is, even though it has

#include <time.h>

I am also getting errors like

implicit declaration of function 'localtime'

in my timeKeeper.c file. And yes, timeKeeper.c #includes timeKeeper.h

Any help is greatly appreciated.

----ADDITIONAL INFORMATION----- I'm using Atmel Studio 6.0 Here is timeKeeper.c

#include "FreeRTOS.h"
#include "task.h"
#include "print_funcs.h"

#include "timeKeeper.h"
#include "telemetryLookup.h"

void timeTask(void* pvParameters);

time_t TIME;
blah blah blah......

----EDIT 2------

I added #include <stdbool.h> and changed Bool to bool in line 6 but the errors are still there.

moooeeeep
  • 31,622
  • 22
  • 98
  • 187
Personofblah
  • 19
  • 1
  • 5
  • This propably depends on includes included before including `tineKeeper.h`. Do you also get these error with a minimal test program on you platform? Btw: What is your platform? – alk Aug 15 '13 at 18:13
  • You might show the start of `timeKeeper.c`up until including `timeKeeper.h`. – alk Aug 15 '13 at 18:14
  • When you post code, adding line numbers to every line does not help; I like to be able to copy-and-paste the code and compile it myself. If you need to refer to a line number from an error message, add a comment like `/* line 6 */` on that line. – Keith Thompson Aug 15 '13 at 18:15
  • 1
    okay Keith I will do that from now on. – Personofblah Aug 15 '13 at 18:16
  • 1
    As Keith said, change `Bool` to `bool` – FrogTheFrog Aug 15 '13 at 18:18
  • please show the content of your `` and the all error messages otherwise this question is pointless. – moooeeeep Aug 22 '13 at 18:23

4 Answers4

5

There is no type Bool in C. There is a type bool, but it's visible only if you have #include <stdbool.h>.

When I add #include <stdbool.h> and change Bool to bool, your code compiles without error. (I also had to delete the line numbers.)

I'd also suggest picking a name other than time for the parameter to isAfter and other functions. time is also the name of a function declared in <time.h>. I don't think it actually causes a conflict in this case, but unique names avoid confusion.

Because Bool is an unrecognized type name, the compiler reports a syntax error on

Bool isAfter(time_t time);

Any errors you see after that are likely to be spurious. If you get syntax errors, start by fixing the error on the earliest reported line and then recompiling.

EDIT:

Based on further comments, adding #include <stdbool.h> and changing Bool to bool doesn't appear to have helped. And the particular message you're getting does seem to imply that time_t is not recognized -- which should certainly not be happening.

Try a simple 2-line source file (and make sure the file name has a .c suffix):

#include <time.h>
time_t foo;

If that fails, the only explanation I can think of is that your compiler and/or runtime library installation is corrupted somehow.

Do you have an option to view preprocessed source? If so, applying it to the above 2-line source should show you the preprocessed contents of <time.h>, which should include a definition for time_t.

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
  • I added `#include ` and changed `Bool` to `bool` but I still get the same errors. – Personofblah Aug 15 '13 at 18:24
  • @Personofblah: That's odd; I made exactly those changes and the header compiled without error. What happens if you compile a one-line `.c` file that has *only* `#include "timeKeeper.h"` ? If that fails, update your question to show us the new source (but keep the original there, because that's what I based my answer on). – Keith Thompson Aug 15 '13 at 18:28
  • Can you recommend a tool to use for single-file compiling? Atmel Studio doesn't have a good way to do that that I know of. – Personofblah Aug 15 '13 at 18:32
  • 1
    @Personofblah: Um, a compiler? I don't know anything about Atmel Studio; I guess it's some kind of IDE. Can you do something like right-click on a source file to compile it? Or can you *temporarily* delete everything but the `#include` from your `timeKeeper.c`? – Keith Thompson Aug 15 '13 at 18:34
  • Silly me you can right-click .c files in Atmel Studio and Compile is right there. Anyways when a blank .c file has `#include "timeKeeper.h"` there are 5 errors. Two of them are `expected ')' before 'time' Line 6 and Line 15` and three of them are `expected '"', ',', ';','asm', or '__attribute__' before SOMEFUNCTION` – Personofblah Aug 15 '13 at 18:47
  • @Personofblah: As I said, you still haven't shown us the file that's giving you those errors. Please update your question to include that file. (The one you have doesn't have the `#include `.) Are you *sure* you changed `Bool` to `bool`? – Keith Thompson Aug 15 '13 at 18:49
  • I updated the original timeKeeper.h file to include the `` thing. The errors are coming from this timeKeeper.h file EVEN WHEN I ADD THE `bool` CHANGES. A blank .c file with `#include ` has the following errors: expected ')' before 'time' expected '"', ',', ';','asm', or '__attribute__' before 'getCurrentTime' expected '"', ',', ';','asm', or '__attribute__' before createTime expected '"', ',', ';','asm', or '__attribute__' before addSeconds expected ')' before 'time' – Personofblah Aug 15 '13 at 18:57
  • The compiler/library is not necessarily corrupted. This is likely a freestanding environment which needs not provide a lot of features, including time stuff. See [my answer](http://stackoverflow.com/a/18267751/1025391). – moooeeeep Aug 16 '13 at 18:31
  • @moooeeeep: Copying the comment I posted on your answer: If there's no ``, the OP would get a fatal error on the `#include `. It would be odd to provide `` but not define `time_t`. – Keith Thompson Aug 16 '13 at 18:36
  • That's true. @Personofblah could you please provide details on your ``. Can you lookup its content? – moooeeeep Aug 16 '13 at 18:52
2

(Assuming you use a standards conforming C compiler, and that we're dealing with a microcontroller, i.e., a freestanding environment.)

Let me quote the C standard:

A conforming freestanding implementation shall accept any strictly conforming program that does not use complex types and in which the use of the features specified in the library clause (clause 7) is confined to the contents of the standard headers <float.h>, <iso646.h>, <limits.h>, <stdarg.h>, <stdbool.h>, <stddef.h>, and <stdint.h>.

The functionality of <time.h> is usually provided by the operating system, however a microcontroller not necessarily runs one. So, you may need to provide this functionality yourself.


Quoting this thread.

Challenge:

damien_d - Feb 27, 2009 - 01:03 AM

Post subject: time.h and/or timing library for C

I am using winavr 20081205.

There appears to be no time.h header file implemented, either by looking at the source, on the homepage at file:///C:/WinAVR-20081205/doc/avr-libc ... dules.html , or when I try to include the header file in a project. For example:

Code:

#include "time.h"

time_t testTime;

Generates the following compiler errors:

Code:

../Clock/clock.c:4:18: error: time.h: No such file or directory ../Clock/clock.c:6: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'testTime'

make: *** [clock.o] Error 1

Response:

Koshchi - Feb 27, 2009 - 02:23 AM

Post subject: RE: time.h and/or timing library for C

Quote: There appears to be no time.h header file implemented

Of course there isn't. The functionality in time.h deals with functions of the operating system that the code is running on. An AVR has no operating system.

Quote: or whatever the time_t would be defined as on the avr-gcc.

Which is the heart of the problem. The full definition of time_t on a system is dependent on the OS.

Acknowledgement:

damien_d - Feb 28, 2009 - 06:03 AM

Post subject: RE: time.h and/or timing library for C

I've learned something new today - only a subset of standard headers are required for non-hosted C environments.

Guess it's time to find a BSD licensed version of time.h (and implementation) and hack it to my heart's content.

moooeeeep
  • 31,622
  • 22
  • 98
  • 187
  • If there's no ``, the OP would get a fatal error on the `#include `. It would be odd to provide `` but not define `time_t`. – Keith Thompson Aug 16 '13 at 18:35
0

There is a definition of Bool at line 6. Maybe you don't include the definition/Typedef ?

Kevin L.
  • 17
  • 1
0

time() is a function defined within time.h but you are also trying to use it as the parameter name in several of your prototypes.

alk
  • 69,737
  • 10
  • 105
  • 255
Ian Miller
  • 593
  • 3
  • 10