Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a reason why C++ does not overload time function so we do not need to write NULL?

Tags:

c++

std

This is not about me being lazy to write

auto t = time(nullptr);

instead of hypothetical

auto t = time();

I am mostly interested if this is possible, and if it is(AFAIK it is easily implementable since C++ supports function overloading) why it has not been done.

I know obvious answers like: use <chrono>, nobody wrote proposal, but I wonder if there is a different reason.

My best guess is that nobody wanted to mess with C library functions.

P.S. I understand that some might want to close this question as too vague, but I feel that it is possible to give relatively objective answer to this question.

like image 572
NoSenseEtAl Avatar asked Dec 25 '19 20:12

NoSenseEtAl


People also ask

Why overloading is not possible in C?

Function overloading is a feature of Object Oriented programming languages like Java and C++. As we know, C is not an Object Oriented programming language. Therefore, C does not support function overloading.

Does C allow overloaded functions?

And C doesn't support Function Overloading.

In which function we Cannot overload the function?

In which of the following we cannot overload the function? Explanation: While overloading the return function, it will rise a error, So we can't overload the return function.

Why overloading is not possible in procedural programming?

Function overloading was introduced in C++, so it is not available in C. Polymorphism is an OOP concept, but C is not object-oriented.


1 Answers

The simple answer is that time(time_t) is “owned” by C rather than by C++: the standard C++ committee doesn’t interfere with the C library unless there are reasons why it is necessary. With C++ you should get a better interface using <chrono> functions.

Also: I don’t think there was a proposal to overload this function. Without a proposal nothing is going to happen and I doubt anybody sufficiently eager to write such a proposal and get it through the process.

like image 192
Dietmar Kühl Avatar answered Sep 28 '22 20:09

Dietmar Kühl