🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.os.msdos.programmer
1 messages
1 total messages Started by Bryan So Sat, 14 Jul 1990 03:11
ANSI C Paste Operator
#1577
Author: Bryan So
Date: Sat, 14 Jul 1990 03:11
52 lines
1980 bytes
I have a tricky way to write generic routines in C, I make use of
the paste operator (##) to paste the target type to the data type 
and operations.  For example, an array of integers can be declared
by
     array(int) a;

and is implemented by
     arrayint a;

The problem is the implementation below only works on Turbo C 2.0
and Turbo C++.  I try it on Microsoft C 5.0 (sorry this is the only
version I have) and BSD UNIX.  It does not compile.  The BSD pre-
processor shows that the line marked with "PROBLEM" is translated to
arrayT instead of arrayint.

Is my method non-standard?  Will Microsoft C 6.0 handle it?

Bryan
__________________________________________________________________________
                                                                 (main.c)
#define T int
#include "array.h"
#undef T

main()
{
     array(int) a;
}
__________________________________________________________________________
                                                                 (array.h)
#if defined(BSD)

#define name2(x,y) _name2(x,y)          /* BSD way to paste            */
#define _name2(x,y) x\
y

#else

#define name2(x,y) _name2(x,y)          /* Need extra redirection, see */
#define _name2(x,y) x##y                /* Turbo C++ include/generic.h */

#endif

#define array(x) name2(array,x)         

typedef struct {
     int size;
     T *vector;                         /* T to be defined in source file */
} array(T);         /* PROBLEM */

/* ... other generic array operations ... */
__________________________________________________________________________
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