Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7400447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:15:06+00:00 2026-05-29T04:15:06+00:00

Possible Duplicate: Operator overloading in C If I have a struct: typedef struct myStruct

  • 0

Possible Duplicate:
Operator overloading in C

If I have a struct:

typedef struct myStruct {
    ...
} myStruct;

myStruct myStructAdd(myStruct a, myStruct b);

I need something like this:

#define myStruct a + myStruct b myStructAdd(a, b)
// NOTE this code does NOT WORK. This is what the question is asking.

To make this syntax valid:

myStruct a;
myStruct b;
myStruct c = a + b;

Is there any way to use a #define to do this?

EDIT:

I’m not asking for alternatives to the + syntax. What I’m asking is if, and how, the preprocessor can be used to rewrite the plus syntax to standard C syntax on compile.

i.e. something like #define myStruct a + myStruct b myStructAdd(a, b) which turns myStructA + myStructB into myStructAdd(myStructA, myStructB) on compile.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T04:15:06+00:00Added an answer on May 29, 2026 at 4:15 am

    Operator overloading simply isn’t a feature of C or Objective-C. C++ allows you to define arbitrary behaviour for operators and custom types. In Objective-C, if two objects can be added together, then usually there is a method for that:

    Foo *result = [foo1 fooByAddingFoo:foo2];
    

    Or, if the class is mutable:

    Foo *foo1 = [Foo fooWithBar:bar];
    
    [foo1 addFoo:foo2];
    

    If operator overloading is a must-have feature, use C++ instead, or use Objective-C++ (but keep in mind that C++ classes and Objective-C objects are totally and fundamentally different).


    Edit:

    The C proprocessor is conceptually very simple, and it knows very, very little about C’s syntax, and nothing at all about C’s types. If you wanted to overload an operator using the preprocessor, then it would have to learn every type (including custom types) used in your code, and it would have to perform static type checking in order to determine which function to invoke, and this is something that is way out of the scope of the preprocessor.

    It’s an interesting idea, but it’s simply not possible.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Ternary conditional operator in Python If I have some code like: x
Possible Duplicate: LINQ Between Operator Dear All, Hi, I need to write this query
Possible Duplicate: Operator overloading in Java I have a small question. If operator <<
Possible Duplicate: Operator overloading I have to code a clock program in which I
Possible Duplicate: Overloading += in c++ Do I need to overload the += operator
Possible Duplicate: Java operator overload In c++, we can perform the operator overloading. But
Possible Duplicate: Operator overloading I didn't find any thing that could help me in
Possible Duplicate: Conditional operator cannot cast implicitly? I have run into a peculiar situation
Possible Duplicate: php == vs === operator Reference - What does this symbol mean
Possible Duplicate: Operator Overloading in C++ as int + obj I override the *

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.