Question

I was able to run code that uses the randomize function without including the time.h library. is it automatically included with some other libraries i might have already included in my code? Below is a list of the libraries I included:

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <string.h> 
#include <io.h>
Was it helpful?

Solution

This is very very specific to the version and implementation of your library. The standard doesn't force any header to include time.h 1 so you cannot rely on that.

In your case, it could be that one of dos.h, io.h, conio.h for example has included time.h (or any other of the headers there for all it's worth).


1 At least not the ones there and not likely in your seemingly ancient library. C11 says threads.h should include time.h

OTHER TIPS

What does <compiler with high warning level> yourcode.c say? My guess would be:

  • either one of the non-standard DOS-specific headers (conio.h, dos.h, io.h, ...) includes it,

  • or there's no declaration at all, i. e. it's not included, in which case your compiler silently and implicitly assumes a function signature (specifically, it assumes a return value of int and whatever type of argument you call it with for the first time).

Note that the latter case is wrong, and you should pay attention not to do it (since it may lead your program invoking undefined behavior). Always compile with all warnings enabled so you can track down such an error.

When C compiler can't find a prototype to a function it assumes it is a function that returns int. It also prints a warning function if you didn't change the default settings.

So. In your case perhaps time.h was included, but be aware that it can cause a lot of problems if it wasn't.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top