🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c.moderated
Article #2385

Re: ada-like naming scheme?

#2385
From: Robert F. Monroe
Date: Mon, 25 Mar 1996 12:21
61 lines
1999 bytes
In article: <4j41gd$nij@solutions.solon.com>  lloyd@upsilon.cs.fsu.edu 
(Justin C Lloyd) writes:
> Does anyone know how to do write a .c file so that you have to include the
> name of c file in any function calls, similar to ada?
> 
> In ada, for instance:
> 
>    ada.text_io.get(x);
> 
> means there is a collection of procedures named ada (a package), and in that
> one named text_io, and in the text_io collection, one called get.

That is similar to what a namespace does in C++. .

> Maybe a way to do this by putting everything in a struct? For instance...

The only way that I can think of doing it in C would be to use 
function pointers as members of the structure and have some sort 
of initialisation/allocation function associated with it. 
Something like:

#include <stdio.h>

extern int Get();
extern int Put(int);

typedef struct
{
	int (*get)();
	int (*put)(int);

} text_io;

text_io *new_text_io(void)
{
	text_io *tio = (text_io*)malloc(sizeof(text_io));

	if (tio == NULL)
		return NULL;

	tio->get = Get;
	tio->put = Put;

	return tio;
}

int main()
{
	text_io *tio = new_text_io();

	if (tio != NULL)
	{
		int i = tio->get();
		tio->put(i);
	}
}

That could be fairly ugly for a lot of purposes but it may be 
useful for something.  Anyway, it does work.

	Bob.
Technical Details
Message-ID: <4j634p$3fs@solutions.solon.com>
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
References: <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:21:45 -0600
Organization: Robert F. Monroe
Sender: clc@solutions.solon.com
Approved: clc@solutions.solon.com
Message-ID: <4j634p$3fs@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 09.49.51
X-Newsreader: Newswin Alpha 0.7
X-Mail2News-Path: disperse.demon.co.uk!post.demon.co.uk!hever.demon.co.uk