Article View: comp.lang.c.moderated
Article #2386Re: ada-like naming scheme?
From: Robert F. Monroe
Date: Mon, 25 Mar 1996 12:22
Date: Mon, 25 Mar 1996 12:22
48 lines
1886 bytes
1886 bytes
As soon as I posted my first idea, I had an even more
twisted thought. If you don't mind completely undermining
the type checking of parameters, try this one. If you are into
Ada, this one will even let you create a "generic" io package!
As far as I know, any ANSI C compiler should handle it fine.
Bob.
PS: Of course I would never do this myself, but I have a
friend...
#include <stdio.h>
#define INTEGER_IO (0)
#define TEXT_IO (1)
extern int INTEGER_IO_Get(void *);
extern int INTEGER_IO_Put(void *);
extern int TEXT_IO_Get(void *);
extern int TEXT_IO_Put(void *);
typedef struct {int (*get)(),(*put)();} io_package;
#define init_io_package(io,t) \
io.get=t##_Get; io.put=t##_Put
int main()
{
int i;
char Buff[80];
io_package IntegerIO, TextIO;
init_io_package(IntegerIO, INTEGER_IO);
init_io_package(TextIO, TEXT_IO);
IntegerIO.get(&i);
IntegerIO.put(&i);
TextIO.get(Buff);
TextIO.put(Buff);
return 0;
}
int INTEGER_IO_Get(void *i) {return scanf("%d", (int*)i);}
int INTEGER_IO_Put(void *i) {return printf("%d", *(int*)i);}
int TEXT_IO_Get(void *buff) {return scanf("%s", (char*)buff);}
int TEXT_IO_Put(void *buff) {return printf("%s", (char*)buff);}
Technical Details
Message-ID:
<4j635s$3h2@solutions.solon.com>Path:
arc1-ca.pugleaf.net!solon.com!not-for-mailReferences:
<4j41gd$nij@solutions.solon.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail From: "Robert F. Monroe" <Robert@hever.demon.co.uk> Newsgroups: comp.lang.c.moderated Subject: Re: ada-like naming scheme? Date: 25 Mar 1996 06:22:20 -0600 Organization: Robert F. Monroe Sender: clc@solutions.solon.com Approved: clc@solutions.solon.com Message-ID: <4j635s$3h2@solutions.solon.com> References: <4j41gd$nij@solutions.solon.com> Reply-To: Robert@hever.demon.co.uk NNTP-Posting-Host: solutions.solon.com X-NNTP-Posting-Host: hever.demon.co.uk X-Broken-Date: Monday, Mar 25, 1996 12.08.50 X-Newsreader: Newswin Alpha 0.7 X-Mail2News-Path: disperse.demon.co.uk!post.demon.co.uk!hever.demon.co.uk