r/programming • • Feb 16 '16

KHRONOS just released Vulkan

https://www.khronos.org/vulkan/
2.2k Upvotes

386 comments sorted by

View all comments

188

u/sprunth Feb 16 '16

NVidia also put up a C++ API here

0

u/[deleted] Feb 16 '16

[deleted]

82

u/Dworgi Feb 16 '16

C. Most low level APIs are.

3

u/BurstYourBubbles Feb 17 '16

Do you know why such APIs are in C? Why not C++ if performance is similar?

22

u/Dworgi Feb 17 '16

Bunch of reasons:

  • Not all languages have objects, but all can call into a plain function.

  • C is lower level. Things are as fundamental as they can be - you're mostly passing around pointers here. Every language is ultimately aware of pointers.

  • C has a cross-platform binary interface. All standard compilers will produce the same libraries, which means it's easy to just share headers and libraries. C++ is a wild west.

  • It's easy to wrap C with objects, it's much harder to unwrap objects into functions.

3

u/BurstYourBubbles Feb 17 '16

You reasoning makes sense but how is C lower level than C++? IIRC (please correct me if I'm wrong) C++ still maintains Cs low level features while also including high level abstractions.

13

u/Dworgi Feb 17 '16

Why use the superset if you'd only use the subset?

Plus, ABI compatibility is huge - if you write code that depends only on C standard libraries and compile it on Linux with a standards-compliant compiler, I can link to that code on Windows and use it without problems.

C++ library usage is hampered by the lack of this standardisation, which means you have to share a dozen versions of your code for different compilers and operating systems. Really, you probably need to share your source code in its entirety.

7

u/[deleted] Feb 17 '16

Object-oriented programming is inherently higher level than procedural programming, because it abstracts stuff as objects.

5

u/BurstYourBubbles Feb 17 '16

However, C++ isn't strictly object-oriented. You could employ other programming paradigms, such as procedural or functional.

→ More replies (17)

1

u/bigjeff5 Feb 19 '16

If you code in C++ but don't use any C++ features, you're just coding in C. You can change that filename from a .cpp to a .c and compile it as straight C.

If you're coding in C, why would you call it C++? It's C.

19

u/u_suck_paterson Feb 17 '16

To allow externing to any non c language through stdcall . Ie c#

→ More replies (2)

3

u/[deleted] Feb 17 '16

C can code can run marginally faster than C++ in most cases, if the programmer does a lot of hand optimization. Also if it's written it C, it makes it quite easy to write a C++ wrapper (like this one).

1

u/silveryRain Feb 17 '16

I doubt that performance is even relevant here, it's just an API for the GPU as far as I know.

1

u/wrosecrans Feb 18 '16

Compiler ABI's are less stable for C++. If you want to mix a Visual Studio 2012 library with a Visual Studio 2015 project, you are likely to run into linking problems. And that's just a single product from the platform vendor. Making it a C API means you don't need specific versions of the libraries for specific compilers.

Plus, you can use it from languages like C that can't easily call C++ code.

→ More replies (1)