Stas Jaro
Stas Jaro

Reputation: 4885

Operator overloading in C?

Is it possible to do operator overloading or something similar (inline function?) in C? I know that c does not support class, but could I make an operator for a struct?

I cannot find anything about this online, because Google will ignore '+' so if I try to google this I only get C++ results.

Upvotes: 3

Views: 5975

Answers (5)

Aditya Naidu
Aditya Naidu

Reputation: 1380

C does not support operator overloading.

Upvotes: 0

ChapMic
ChapMic

Reputation: 28144

C++ introduced an important and interesting feature which is operator overloading.

So you will have to use it if you want to use this feature.

Upvotes: 1

Caner
Caner

Reputation: 59238

No it is not possible.

By the way, you can remove C++ from google search results if you add -"C++" to your search query.

Upvotes: 6

Mark Robinson
Mark Robinson

Reputation: 3165

C does not support operator overloading or having functions inside structs. You will need to use C++ for those features.

Upvotes: 0

Carl Norum
Carl Norum

Reputation: 225032

No, you can't do that in C. Use C++ if you want to overload operators.

You can put function pointers inside a structure if you want a sort of C++ object-like behaviour.

Upvotes: 9

Related Questions