[Courses] C Programming For Absolute Beginners, Lesson 5A: All About Functions, Part 2

Akkana Peck akkana at shallowsky.com
Tue Apr 3 17:09:16 UTC 2012


Carla Schroder writes:
> I don't see how this makes a case against creating unique function names. 
> Sure, you can do it.  Regardless of any circumstances where duplicate function 
> names would not cause a program to run incorrectly, why would you want the 
> confusion?

A couple of arguments supporting Carla's position:

It's not uncommon to start out with a static function, local to just
one file ... and then as your file grows and you add functionality
to your program, eventually you realize that the function would be
useful from other files as well. If you've kept the function name
unique, that's easy. If you haven't, you'll have to go through and
rename it everywhere it's used.

Less common, but could still happen: what if you need to use the
external function with the same name as your internal static one?
You can't, within that file, unless you rename your static function.

> > > 5--Return multiple values
> > 
> > Item 5 should be excluded from the list. Speaking technically, all
> > functions in C return one value and one value only. This might be a
> > struct containing other data objects, yet even in such a case it is only
> > one value that is returned by the function (the memory address of the
> > struct). I suppose one could argue semantic nuances here, but even on
> > the highest level we recognize that a "return" statements returns only
> > one evaluated result.
> 
> Nah, it stays on the list :). Whatever the semantic nuances, which are good to 
> understand clearly, it's still operating with multiple returned values.

This time I'll side with Christopher. Returning multiple values
requires extra set-up, like defining a struct and allocating memory
for it (and then documenting who is responsible for freeing that
memory), or declaring variables then passing in pointers so the
function can modify them.  No matter how you do it, it's not
something done casually like it is in some languages.

	...Akkana


More information about the Courses mailing list