l i n u x - u s e r s - g r o u p - o f - d a v i s
Next Meeting:
July 7: Social gathering
Next Installfest:
Latest News:
Jun. 14: June LUGOD meeting cancelled
Page last updated:
2010 Feb 11 00:23

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] overloading in C
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] overloading in C

On Wed, Feb 10, 2010 at 10:10:31PM -0800, Brian Lavender wrote:
> I guess in C, you can't overload a function?

You could use "...", like prinf() and scanf() use. ;)

What I end up doing (and have seen other C-based APIs do) is
something like this:

  void oldfunction(type1 arg1)
  { ...some code... }

oops, I need two args!  Rewrite time!

  void newfunction(type1 arg1, type2 arg2)
  { ...some code... }

  void oldfunction(type1 arg1)
    newfunction(arg1, somedefault);

So now, anything that used oldfunction() still works as-is
(API didn't change), but if I need the additional arguments,
I can call the newer function (which really started life as
a rename of the old function, then had some code added to it).

It's kind of lame.  I do appreciate PHP letting me only
send args I need to, and providing defaults when declaring
the function.  e.g.:

  function getsomething($what, $how_many_days_ago = 7)
  { ... some code ...}

I can call it as:

  $thisweek = getsomething("cookies");
  $today = getsomething("cookies", 1);

This also means the default can change w/o the callers caring.
(Good or bad, depending ;) )

Rambling, sorry :)

vox-tech mailing list

LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
EDGE Tech Corp.
For donating some give-aways for our meetings.