Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Overriding Function in C

Posted on 1999-07-02
Medium Priority
Last Modified: 2010-04-15
Is there a way to have an overriding function in C?
I want to have one function that has parameters (int x, int y, int attr), and one function that has the same name with parameters (int x, int y, int sx, int sy).
Question by:screwdriver
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 1263149
No, it is not possible. That works only in C++. However, since C++ is downwards compatible to C in every respect (almost), how about simply compiling under C++, if it's so important for you to overload?
LVL 10

Accepted Solution

rbr earned 100 total points
ID: 1263150
There will be no way in C to override functions. One way to simulate this is

struct my_struct1 {
      int x;
      int y;
      int attr;
struct my_struct2 {
      int x;
      int y;
      int sx;
      int sy;

void my_func (void *data,int which_func)
      switch (which_func) {
            case 1:
                  my_func_1 ((struct my_struct1 *)data);
            case 2:
                  my_func_2 ((struct my_struct2 *)data);

Expert Comment

ID: 1263151
Why not have the second function, and just check to see if there were parameters passed on for the last two?  If they are both NULL, then do the first function, if not, then do the second.  Or have a third parameter which is a BOOL to toggle..


Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question