🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.lang.c.moderated
2 messages
2 total messages Started by Matthew Heaney Thu, 18 Apr 1996 12:30
Coding Idioms For Functions Having External Linkage
#2614
Author: Matthew Heaney
Date: Thu, 18 Apr 1996 12:30
45 lines
1682 bytes
I'm interested in learing what the C idioms are for "extern" functions.

The reason I ask is because external functions have global scope, and some
convention has to be established to avoid name clashes.

Here is a fragment of a (bounded) stack I wrote:

#ifndef BOUNDEDINTSTACK_H
#define BOUNDEDINTSTACK_H

typedef struct BoundedIntStackRep* BoundedIntStack;

void newBoundedIntStack (int maxDepth);

int topBoundedIntStack (BoundedIntStack stack);

void popBoundedIntStack (BoundedIntStack stack);

void pushBoundedIntStack (BoundedIntStack stack, int item);

...

#endif BOUNDEDINTSTACK_H

I'm interested in knowing what coding conventions a seasoned
C programmer would have used to code this abstract data type.

For example, do you qualify the subprograms before or after the
"real" name:

int topBoundedIntStack (BoundedIntStack stack);

   vs.

int BoundedIntStackTop (BoundedIntStack stack);

Would you have coded a different stack module for each kind of
native type?  Or just use a BoundedLongStack for all integer types
(letting the compiler automatically coerce the item into type long)?

Steve Summit gave a recommendation in his book on how to
code an abstract data type.  Steve: is the example I provided what
you had in mind?

matt
Re: Coding Idioms For Functions Having External Linkage
#2629
Author: Tom McGlynn
Date: Sat, 20 Apr 1996 18:22
15 lines
1175 bytes
I would like to see the major prefix followed by minor prefixes and
function description as in BoundeIntStackPop and BoundedIntStackTop.
That way, in an alphabetical listing you see all related operations
together.

I would also implement a generic stack consisting of elements of
type (void *).  Then you can use the module and its data structure
for any type.

As an example, consider standard C library routines like bsearch,
hsearch, and tsearch (for binary search trees).

--
The preceding is my opinion and not necessarily the opinion of my
employer.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads