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

x
?
Solved

Overriding Function in C

Posted on 1999-07-02
3
Medium Priority
?
228 Views
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).
0
Comment
Question by:screwdriver
[X]
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
3 Comments
 
LVL 2

Expert Comment

by:Slarti
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?
0
 
LVL 10

Accepted Solution

by:
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);
            break;
            case 2:
                  my_func_2 ((struct my_struct2 *)data);
            break;
}
            
0
 
LVL 3

Expert Comment

by:BudVVeezer
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..

~Aaron
0

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