Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why don't win32 API functions have overloads and instead use Ex as suffix?

The win32 API has for example two methods StrFormatByteSize and StrFormatByteSizeEx. Even though both the methods symantically do the same thing and the Ex counter part only offers a new parameter to slightly change the behavior then couldn't they have two overloads of the same function?

Is it a limitation of c/c++ or what is the possible reason for such an awkward convention?

like image 350
Muhammad Hasan Khan Avatar asked Nov 26 '22 23:11

Muhammad Hasan Khan


2 Answers

The Win32 API is a C (not C++) API. The C language doesn't support overloaded functions.


Complete aside: The Win32 API uses __stdcall-decorated functions, which include the number of bytes of parameters as part of the function name. __stdcall is not part of the C language, but Windows linkers have to know about it.

Microsoft could have used this to implement some kind of overloading, but (since a lot of languages don't understand overloading) that would limit the number of languages that could be used to program Windows.

like image 69
Roger Lipscombe Avatar answered Nov 29 '22 11:11

Roger Lipscombe


The C language doesn't support function overloading at all.

like image 41
Greg Hewgill Avatar answered Nov 29 '22 12:11

Greg Hewgill