Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"Flattery is all right -- if you don't inhale." -- Adlai Stevenson


devel / comp.lang.c / Re: Include files with the same definitions

SubjectAuthor
* Include files with the same definitionsSpyridon Metaxas
+* Re: Include files with the same definitionsStefan Ram
|`- Re: Include files with the same definitionsStefan Ram
+- Re: Include files with the same definitionsBart
+- Re: Include files with the same definitionsLew Pitcher
+- Re: Include files with the same definitionsAndrey Tarasevich
+* Re: Include files with the same definitionsJames Kuyper
|`* Re: Include files with the same definitionsÖö Tiib
| `* Re: Include files with the same definitionsjames...@alumni.caltech.edu
|  `- Re: Include files with the same definitionsRichard Damon
+- Re: Include files with the same definitionsManfred
+- Re: Include files with the same definitionsRichard Damon
+* Re: Include files with the same definitionsBonita Montero
|`- Re: Include files with the same definitionsVir Campestris
`- Re: Include files with the same definitionsChris M. Thomasson

1
Include files with the same definitions

<ss4por$ogn$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20025&group=comp.lang.c#20025

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!fs4vz7lwhQCwq5L3H1slGg.user.46.165.242.75.POSTED!not-for-mail
From: SMe...@somewhere.world (Spyridon Metaxas)
Newsgroups: comp.lang.c
Subject: Include files with the same definitions
Date: Mon, 17 Jan 2022 22:14:51 -0000 (UTC)
Organization: Aioe.org NNTP Server
Message-ID: <ss4por$ogn$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="25111"; posting-host="fs4vz7lwhQCwq5L3H1slGg.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
X-Notice: Filtered by postfilter v. 0.9.2
 by: Spyridon Metaxas - Mon, 17 Jan 2022 22:14 UTC

I have the following problem:

Within the same C executable I need to interact with two
different modules, A and B, that expose the same standardized API. Which
module is to be used is something to be decided at run time; for the
purposes of this discussion, it does not matter how or why.

In order to be able to interact with those modules I need to use
the include files IA and IAB, respectively, that they provide. I cannot
include them both, for they both define many of the same data structures
and function prototypes. However, because of proprietary extensions, each
defines stuff that is not present in the other. The thing is, at run time
I will need to be able to use such extensions: when the program is run I
will know whether A or B is to be used, and selecting what extension to
use will be easy.

The bottom line, I need to include both IA and IB at compile
time, but doing so would result in compile time errors.

How can one deal with this situation? I guess one could create a
new include file IC containing the stuff common to IA and IB, plus their
differences. However, that is a horrible hack fraught with danger, for,
among other things, there is no guarantee that bits that differ between
IA and IB will be compatible.

There has to be a better, more elegant way to deal with this.

Re: Include files with the same definitions

<modules-20220117233207@ram.dialup.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20026&group=comp.lang.c#20026

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.c
Subject: Re: Include files with the same definitions
Supersedes: <modules-20220117233003@ram.dialup.fu-berlin.de>
Date: 17 Jan 2022 22:34:00 GMT
Organization: Stefan Ram
Lines: 24
Expires: 1 Apr 2022 11:59:58 GMT
Message-ID: <modules-20220117233207@ram.dialup.fu-berlin.de>
References: <ss4por$ogn$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de yJId+uTn+RF+50yFaUAsSA/GGmeGZIVLLNcjnF1UnILtkv
X-Copyright: (C) Copyright 2022 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Mon, 17 Jan 2022 22:34 UTC

Supersedes: <modules-20220117233003@ram.dialup.fu-berlin.de>

Spyridon Metaxas <SMet@somewhere.world> writes:
> Within the same C executable I need to interact with two
>different modules, A and B, that expose the same standardized API. Which
>module is to be used is something to be decided at run time; for the
>purposes of this discussion, it does not matter how or why.

Well, this is exactly what object-oriented programming is
made for. Run-time polymorphism.

What you could do: Have three compilation units for your program:

my_A_wrapper.c
my_B_wrapper.c
main.c

.

my_A_wrapper.c #includes IA.h and offers a service/struct to access A.
my_B_wrapper.c #includes IB.h and offers a service/struct to access B.
main.c can then decide at runtime which service/struct to use.

Re: Include files with the same definitions

<compilation_unit-20220117235321@ram.dialup.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20027&group=comp.lang.c#20027

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.c
Subject: Re: Include files with the same definitions
Date: 17 Jan 2022 22:54:14 GMT
Organization: Stefan Ram
Lines: 17
Expires: 1 Apr 2022 11:59:58 GMT
Message-ID: <compilation_unit-20220117235321@ram.dialup.fu-berlin.de>
References: <ss4por$ogn$1@gioia.aioe.org> <modules-20220117233207@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de 2PkhyR0Rw0fcJ8DqHsaHrgRsLq61B/8UyCrkOHTCqfqi4L
X-Copyright: (C) Copyright 2022 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Mon, 17 Jan 2022 22:54 UTC

ram@zedat.fu-berlin.de (Stefan Ram) writes:
>What you could do: Have three compilation units for your program:
>my_A_wrapper.c
>my_B_wrapper.c
>main.c
>.

Well, "compilation units" might not have been the correct term here,
read ".c files" instead. The five files to be written would act. be:

my_A_wrapper.h,
my_A_wrapper.c,
my_B_wrapper.h,
my_B_wrapper.c, and
main.c.

Re: Include files with the same definitions

<ss4sql$dls$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20028&group=comp.lang.c#20028

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (Bart)
Newsgroups: comp.lang.c
Subject: Re: Include files with the same definitions
Date: Mon, 17 Jan 2022 23:07:01 +0000
Organization: A noiseless patient Spider
Lines: 57
Message-ID: <ss4sql$dls$1@dont-email.me>
References: <ss4por$ogn$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 17 Jan 2022 23:07:01 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="1acecea5448c2ff21f8725e2459af25e";
logging-data="14012"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19zE1WrPLps2cdzLotlYXiY9EpI74wqghU="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:nMT3ouih116lKvopr/Nl1/eSvao=
In-Reply-To: <ss4por$ogn$1@gioia.aioe.org>
 by: Bart - Mon, 17 Jan 2022 23:07 UTC

On 17/01/2022 22:14, Spyridon Metaxas wrote:
> I have the following problem:
>
> Within the same C executable I need to interact with two
> different modules, A and B, that expose the same standardized API. Which
> module is to be used is something to be decided at run time; for the
> purposes of this discussion, it does not matter how or why.
>
> In order to be able to interact with those modules I need to use
> the include files IA and IAB, respectively, that they provide. I cannot
> include them both, for they both define many of the same data structures
> and function prototypes. However, because of proprietary extensions, each
> defines stuff that is not present in the other. The thing is, at run time
> I will need to be able to use such extensions: when the program is run I
> will know whether A or B is to be used, and selecting what extension to
> use will be easy.
>
> The bottom line, I need to include both IA and IB at compile
> time, but doing so would result in compile time errors.

But you can compile a program that includes either IA or IB? In that
case, what happens with the stuff that is missing because it's in the
other header; isn't it missed in the rest of the program, and cause errors?

> How can one deal with this situation? I guess one could create a
> new include file IC containing the stuff common to IA and IB, plus their
> differences. However, that is a horrible hack fraught with danger, for,
> among other things, there is no guarantee that bits that differ between
> IA and IB will be compatible.
>
> There has to be a better, more elegant way to deal with this.

You can provide two executables and a way to select which to run. Or
relegate the contents of A and B to external, shared libraries, then
provide both libraries. However the common parts have to be compatible
if there is one main executable.

Another way (I think Stefan Ram suggested this) is for both modules to
have a set of wrapper functions to provide a compatible interface to A
and B, then those functions form part of the shared libraries.

In might to be possible to have both statically linked into the one
executable, if they won't interfere with each other. But then access
might have to be through a set of function pointers set to either A
functions or B functions. It gets messy.

Yet another is to just compile when the program is 'run'; that is a
small program that determines which of A and B is needed, and compiles
the right modules, then invokes the executable. (Will the A/B choice be
done just once, or each time it's run?)

This can also get messy if your app is sprawling and needs a complex
build (the end user will need all the right tools as well). But if it
can be tidily contained, and you use a very small, very fast compiler
like Tiny C which works instantly, users may not even notice.

Re: Include files with the same definitions

<ss4uid$260$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20029&group=comp.lang.c#20029

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: lew.pitc...@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.lang.c
Subject: Re: Include files with the same definitions
Date: Mon, 17 Jan 2022 23:36:45 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <ss4uid$260$1@dont-email.me>
References: <ss4por$ogn$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 17 Jan 2022 23:36:45 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="dc0114b20434b02d318d0de5059d806a";
logging-data="2240"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Y/zZ08iXrqFsEVZGJYYn83vMs0RMYb54="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:85vG4C9JR7Pd48SWVX3hddlBuss=
 by: Lew Pitcher - Mon, 17 Jan 2022 23:36 UTC

On Mon, 17 Jan 2022 22:14:51 +0000, Spyridon Metaxas wrote:

> I have the following problem:
>
> Within the same C executable I need to interact with two
> different modules, A and B, that expose the same standardized API. Which
> module is to be used is something to be decided at run time; for the
> purposes of this discussion, it does not matter how or why.
>
> In order to be able to interact with those modules I need to use
> the include files IA and IAB, respectively, that they provide. I cannot
> include them both, for they both define many of the same data structures
> and function prototypes. However, because of proprietary extensions, each
> defines stuff that is not present in the other. The thing is, at run time
> I will need to be able to use such extensions: when the program is run I
> will know whether A or B is to be used, and selecting what extension to
> use will be easy.
>
> The bottom line, I need to include both IA and IB at compile
> time, but doing so would result in compile time errors.
>
> How can one deal with this situation? I guess one could create a
> new include file IC containing the stuff common to IA and IB, plus their
> differences. However, that is a horrible hack fraught with danger, for,
> among other things, there is no guarantee that bits that differ between
> IA and IB will be compatible.
>
> There has to be a better, more elegant way to deal with this.

Break the code that uses interface IA out into a separate source file,
and ensure that the source file #include's the definitions for interface
IA.

Do the same for the code that uses interface IB: break that code out into
it's own separate source file and ensure that the source file #include's
the definitions for interface IB.

Compile each of your main source file, the IA interface source and the IB
interface file separately. Then link the resulting object files together
with any support libraries that are necessary for proper execution.

--
Lew Pitcher
"In Skills, We Trust"

Re: Include files with the same definitions

<ss53l4$h5h$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20031&group=comp.lang.c#20031

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: andreyta...@hotmail.com (Andrey Tarasevich)
Newsgroups: comp.lang.c
Subject: Re: Include files with the same definitions
Date: Mon, 17 Jan 2022 17:03:31 -0800
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <ss53l4$h5h$1@dont-email.me>
References: <ss4por$ogn$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 18 Jan 2022 01:03:32 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="35a3b91cf78807077e7b8c9ec717ba3b";
logging-data="17585"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+MAPKcoF4g1idNUQ/h7Iit"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:cM4mgl1g/nTV0dtdjGvVRvuEvlE=
In-Reply-To: <ss4por$ogn$1@gioia.aioe.org>
Content-Language: en-US
 by: Andrey Tarasevich - Tue, 18 Jan 2022 01:03 UTC

On 1/17/2022 2:14 PM, Spyridon Metaxas wrote:
> Within the same C executable I need to interact with two
> different modules, A and B, that expose the same standardized API. Which

What is a "module" in this case? A dynamic library? A static library?
Just a bunch of source files? A single source file?

--
Best regards,
Andrey Tarasevich

Re: Include files with the same definitions

<ss53rh$jnj$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20032&group=comp.lang.c#20032

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jameskuy...@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.lang.c
Subject: Re: Include files with the same definitions
Date: Mon, 17 Jan 2022 20:06:56 -0500
Organization: A noiseless patient Spider
Lines: 45
Message-ID: <ss53rh$jnj$1@dont-email.me>
References: <ss4por$ogn$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 18 Jan 2022 01:06:58 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="0cf87e0619cf77d8cf982ac9752897c4";
logging-data="20211"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18J3l1m0S+OIMqAw4cCe6WNowbawWpq5nU="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
Cancel-Lock: sha1:Fv4pa2Cr5+BncAd/WHfAG4Ti3mg=
In-Reply-To: <ss4por$ogn$1@gioia.aioe.org>
Content-Language: en-US
 by: James Kuyper - Tue, 18 Jan 2022 01:06 UTC

On 1/17/22 5:14 PM, Spyridon Metaxas wrote:
> I have the following problem:
>
> Within the same C executable I need to interact with two
> different modules, A and B, that expose the same standardized API. Which
> module is to be used is something to be decided at run time; for the
> purposes of this discussion, it does not matter how or why.
>
> In order to be able to interact with those modules I need to use
> the include files IA and IAB, respectively, that they provide. I cannot
> include them both, for they both define many of the same data structures
> and function prototypes. However, because of proprietary extensions, each
> defines stuff that is not present in the other. The thing is, at run time
> I will need to be able to use such extensions: when the program is run I
> will know whether A or B is to be used, and selecting what extension to
> use will be easy.
>
> The bottom line, I need to include both IA and IB at compile
> time, but doing so would result in compile time errors.
>
> How can one deal with this situation? I guess one could create a
> new include file IC containing the stuff common to IA and IB, plus their
> differences. However, that is a horrible hack fraught with danger, for,
> among other things, there is no guarantee that bits that differ between
> IA and IB will be compatible.
>
> There has to be a better, more elegant way to deal with this.
>

Is the problem only in the header files? If so, the solution is
relatively simple: have one file that #includes A.h, and have all code
that depends upon declarations from A.h in that file. Have a second file
that #includes B.h, and have all code that depends upon declarations
from B.h in that file. Those files should declare wrapper functions that
support the same interface to the rest of your code, hiding the
differences between A and B.

However, your wording left me wondering whether you might have
incorrectly expressed a problem that's actually harder to deal with. Is
it not just the headers, but also the corresponding object files, that
are incompatible in ways that prevent both of them from being linked
into the same program - do they declare functions or objects with
external linkage that have the same name? If so, you've got a much more
complicated problem to deal with.

Re: Include files with the same definitions

<ss5goe$on5$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20033&group=comp.lang.c#20033

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!/h8BftqU66Br+skYlTFpYQ.user.46.165.242.75.POSTED!not-for-mail
From: non...@add.invalid (Manfred)
Newsgroups: comp.lang.c
Subject: Re: Include files with the same definitions
Date: Tue, 18 Jan 2022 05:47:09 +0100
Organization: Aioe.org NNTP Server
Message-ID: <ss5goe$on5$1@gioia.aioe.org>
References: <ss4por$ogn$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="25317"; posting-host="/h8BftqU66Br+skYlTFpYQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Manfred - Tue, 18 Jan 2022 04:47 UTC

On 1/17/2022 11:14 PM, Spyridon Metaxas wrote:
> I have the following problem:
>
> Within the same C executable I need to interact with two
> different modules, A and B, that expose the same standardized API. Which
> module is to be used is something to be decided at run time; for the
> purposes of this discussion, it does not matter how or why.
>
> In order to be able to interact with those modules I need to use
> the include files IA and IAB, respectively, that they provide. I cannot
> include them both, for they both define many of the same data structures
> and function prototypes. However, because of proprietary extensions, each
> defines stuff that is not present in the other. The thing is, at run time
> I will need to be able to use such extensions: when the program is run I
> will know whether A or B is to be used, and selecting what extension to
> use will be easy.
>
> The bottom line, I need to include both IA and IB at compile
> time, but doing so would result in compile time errors.
>
> How can one deal with this situation? I guess one could create a
> new include file IC containing the stuff common to IA and IB, plus their
> differences. However, that is a horrible hack fraught with danger, for,
> among other things, there is no guarantee that bits that differ between
> IA and IB will be compatible.
>
> There has to be a better, more elegant way to deal with this.
>

There is a contradiction in the problem exposition that might give some
hint about how to solve the problem:
You say A and B "expose the same standardized API", but IA.h and IB.h
are different and not compatible with each other, so they don't export
the same standardized API.
(Header files in C are pretty much the interface layer of their
respective modules)

You have to factor out the API that is really common between the two
(their MCD if you like), for example as James has suggested, and work
from there.

The second problem is about symbols: what do you mean by "standardized
API", is it e.g. a set of functions with the same names and signature or
signature only?
If you have a function foo in each module, with the same signature but
different body, you can't link them both in the same executable.

One solution that comes to mind would be using dynamic linking (.so in
*NIX or .DLL in Windows), but that's one step further.

Re: Include files with the same definitions

<e364aacb-1b8b-4cab-b716-432eaad1bcb1n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20034&group=comp.lang.c#20034

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a37:86c5:: with SMTP id i188mr14246417qkd.485.1642497383111;
Tue, 18 Jan 2022 01:16:23 -0800 (PST)
X-Received: by 2002:ac8:6755:: with SMTP id n21mr16693836qtp.322.1642497381698;
Tue, 18 Jan 2022 01:16:21 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Tue, 18 Jan 2022 01:16:21 -0800 (PST)
In-Reply-To: <ss53rh$jnj$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=84.50.190.130; posting-account=pysjKgkAAACLegAdYDFznkqjgx_7vlUK
NNTP-Posting-Host: 84.50.190.130
References: <ss4por$ogn$1@gioia.aioe.org> <ss53rh$jnj$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <e364aacb-1b8b-4cab-b716-432eaad1bcb1n@googlegroups.com>
Subject: Re: Include files with the same definitions
From: oot...@hot.ee (Öö Tiib)
Injection-Date: Tue, 18 Jan 2022 09:16:23 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 58
 by: Öö Tiib - Tue, 18 Jan 2022 09:16 UTC

On Tuesday, 18 January 2022 at 03:07:11 UTC+2, james...@alumni.caltech.edu wrote:
> On 1/17/22 5:14 PM, Spyridon Metaxas wrote:
> > I have the following problem:
> >
> > Within the same C executable I need to interact with two
> > different modules, A and B, that expose the same standardized API. Which
> > module is to be used is something to be decided at run time; for the
> > purposes of this discussion, it does not matter how or why.
> >
> > In order to be able to interact with those modules I need to use
> > the include files IA and IAB, respectively, that they provide. I cannot
> > include them both, for they both define many of the same data structures
> > and function prototypes. However, because of proprietary extensions, each
> > defines stuff that is not present in the other. The thing is, at run time
> > I will need to be able to use such extensions: when the program is run I
> > will know whether A or B is to be used, and selecting what extension to
> > use will be easy.
> >
> > The bottom line, I need to include both IA and IB at compile
> > time, but doing so would result in compile time errors.
> >
> > How can one deal with this situation? I guess one could create a
> > new include file IC containing the stuff common to IA and IB, plus their
> > differences. However, that is a horrible hack fraught with danger, for,
> > among other things, there is no guarantee that bits that differ between
> > IA and IB will be compatible.
> >
> > There has to be a better, more elegant way to deal with this.
> >
> Is the problem only in the header files? If so, the solution is
> relatively simple: have one file that #includes A.h, and have all code
> that depends upon declarations from A.h in that file. Have a second file
> that #includes B.h, and have all code that depends upon declarations
> from B.h in that file. Those files should declare wrapper functions that
> support the same interface to the rest of your code, hiding the
> differences between A and B.
>
> However, your wording left me wondering whether you might have
> incorrectly expressed a problem that's actually harder to deal with. Is
> it not just the headers, but also the corresponding object files, that
> are incompatible in ways that prevent both of them from being linked
> into the same program - do they declare functions or objects with
> external linkage that have the same name? If so, you've got a much more
> complicated problem to deal with.

Yes, the OP as quoted above said that modules "both define many of the
same data structures and function prototypes". Most likely "same" there
means on several cases "with same name" and not "with same name
and definition". As the identified pain point was about #including the
header files then that indicates desire to link both the "modules"
to same program. So there will be "many" one definition rule violations
if to attempt to link the modules into same program, several of what
are not simple to fix.

Therefore without capability to either rename half of the "many" or to
consolidate both halves of "many" under same, one definition the OP
can not link the modules into same program and so has perhaps to
use things like multiprocessing to solve the issue.

Re: Include files with the same definitions

<b0zFJ.10345$jb4.7158@fx24.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20035&group=comp.lang.c#20035

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx24.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0)
Gecko/20100101 Thunderbird/91.5.0
Subject: Re: Include files with the same definitions
Content-Language: en-US
Newsgroups: comp.lang.c
References: <ss4por$ogn$1@gioia.aioe.org>
From: Rich...@Damon-Family.org (Richard Damon)
In-Reply-To: <ss4por$ogn$1@gioia.aioe.org>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 55
Message-ID: <b0zFJ.10345$jb4.7158@fx24.iad>
X-Complaints-To: abuse@easynews.com
Organization: Forte - www.forteinc.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Tue, 18 Jan 2022 08:11:39 -0500
X-Received-Bytes: 3575
 by: Richard Damon - Tue, 18 Jan 2022 13:11 UTC

On 1/17/22 5:14 PM, Spyridon Metaxas wrote:
> I have the following problem:
>
> Within the same C executable I need to interact with two
> different modules, A and B, that expose the same standardized API. Which
> module is to be used is something to be decided at run time; for the
> purposes of this discussion, it does not matter how or why.
>
> In order to be able to interact with those modules I need to use
> the include files IA and IAB, respectively, that they provide. I cannot
> include them both, for they both define many of the same data structures
> and function prototypes. However, because of proprietary extensions, each
> defines stuff that is not present in the other. The thing is, at run time
> I will need to be able to use such extensions: when the program is run I
> will know whether A or B is to be used, and selecting what extension to
> use will be easy.
>
> The bottom line, I need to include both IA and IB at compile
> time, but doing so would result in compile time errors.
>
> How can one deal with this situation? I guess one could create a
> new include file IC containing the stuff common to IA and IB, plus their
> differences. However, that is a horrible hack fraught with danger, for,
> among other things, there is no guarantee that bits that differ between
> IA and IB will be compatible.
>
> There has to be a better, more elegant way to deal with this.
>

Simple description:

If IA.h and IB.h both need a 'c' which is the SAME between the two of
them, it needs to be in a seperate include file IC.h

If IA.h and IB.h both need a 'd' which DIFFERS between the two of them,
you are out of luck, you can't have two different things with the same
global name.

Basically, when writing a reusable header, anything 'unique' to that
header needs to be put into some sort of locally allocated namespace
reserved for that header (and its associated code), and anything that it
needs to share in common with other stuff should be in a separate common
header defined for that purpose.

If you read the Standard, you will notice that it carefully defines what
symbols the implementation might use, and thus are not available for the
application. In the same way, a 'module' designer needs to carve out a
name space of symbols that they will reserve for themselves, and only
use those at the global level. Two modules that reserve the some of the
same symbols are not compatible with each other, unless that part of the
resservation is in a seperate header that they agree on.

For C, it is common to just add a short prefix to all names that is
hopefully unique.

Re: Include files with the same definitions

<f2af1d8f-dce1-461a-b4c4-e188d825b3ccn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20036&group=comp.lang.c#20036

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:6214:c89:: with SMTP id r9mr23882295qvr.116.1642519869881;
Tue, 18 Jan 2022 07:31:09 -0800 (PST)
X-Received: by 2002:ac8:7fc2:: with SMTP id b2mr4558790qtk.34.1642519869674;
Tue, 18 Jan 2022 07:31:09 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!1.us.feeder.erje.net!2.us.feeder.erje.net!feeder.erje.net!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Tue, 18 Jan 2022 07:31:09 -0800 (PST)
In-Reply-To: <e364aacb-1b8b-4cab-b716-432eaad1bcb1n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=108.48.119.9; posting-account=Ix1u_AoAAAAILVQeRkP2ENwli-Uv6vO8
NNTP-Posting-Host: 108.48.119.9
References: <ss4por$ogn$1@gioia.aioe.org> <ss53rh$jnj$1@dont-email.me> <e364aacb-1b8b-4cab-b716-432eaad1bcb1n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f2af1d8f-dce1-461a-b4c4-e188d825b3ccn@googlegroups.com>
Subject: Re: Include files with the same definitions
From: jameskuy...@alumni.caltech.edu (james...@alumni.caltech.edu)
Injection-Date: Tue, 18 Jan 2022 15:31:09 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 50
 by: james...@alumni.calt - Tue, 18 Jan 2022 15:31 UTC

On Tuesday, January 18, 2022 at 4:16:31 AM UTC-5, Öö Tiib wrote:
> On Tuesday, 18 January 2022 at 03:07:11 UTC+2, james...@alumni.caltech.edu wrote:
> > On 1/17/22 5:14 PM, Spyridon Metaxas wrote:
> > > I have the following problem:
> > >
> > > Within the same C executable I need to interact with two
> > > different modules, A and B, that expose the same standardized API. Which
> > > module is to be used is something to be decided at run time; for the
> > > purposes of this discussion, it does not matter how or why.
> > >
> > > In order to be able to interact with those modules I need to use
> > > the include files IA and IAB, respectively, that they provide. I cannot
> > > include them both, for they both define many of the same data structures
> > > and function prototypes.
....
> > However, your wording left me wondering whether you might have
> > incorrectly expressed a problem that's actually harder to deal with. Is
> > it not just the headers, but also the corresponding object files, that
> > are incompatible in ways that prevent both of them from being linked
> > into the same program - do they declare functions or objects with
> > external linkage that have the same name? If so, you've got a much more
> > complicated problem to deal with.
> Yes, the OP as quoted above said that modules "both define many of the
> same data structures and function prototypes". Most likely "same" there
> means on several cases "with same name" and not "with same name
> and definition" ...

I think that's definitely a possibility, but I don't think his description was
sufficiently clear to guarantee that he's facing this problem. Both headers might
define the same struct type, and provide two different declarations of the same
function, in addition to declaring additional identifiers that are unique to each
module. That's why I asked about it, rather than assuming one answer or the
other. That would be poor design: the shared features should be declared once
in a separate header file, with it's own header guards to prevent doubled
declarations. However, I'd seen worse examples of poor design, so I wouldn't
rule out that possibility.

Re: Include files with the same definitions

<ss6uil$6hj$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20037&group=comp.lang.c#20037

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: Include files with the same definitions
Date: Tue, 18 Jan 2022 18:49:09 +0100
Organization: A noiseless patient Spider
Lines: 1
Message-ID: <ss6uil$6hj$1@dont-email.me>
References: <ss4por$ogn$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 18 Jan 2022 17:49:09 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="74c8d8f1226ebe3ad1bbc411e51bfd26";
logging-data="6707"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19kAC8WaakyzJCCvnWpAKf2fZqLNtbSxks="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:9W2sIMkQDhNVtEEvehn30Q4jQ+I=
In-Reply-To: <ss4por$ogn$1@gioia.aioe.org>
Content-Language: de-DE
 by: Bonita Montero - Tue, 18 Jan 2022 17:49 UTC

That's easy to solve in C++ with inheritance.

Re: Include files with the same definitions

<G4KFJ.50950$Q11.38954@fx33.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20038&group=comp.lang.c#20038

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!border1.nntp.dca1.giganews.com!nntp.giganews.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx33.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0)
Gecko/20100101 Thunderbird/91.5.0
Subject: Re: Include files with the same definitions
Content-Language: en-US
Newsgroups: comp.lang.c
References: <ss4por$ogn$1@gioia.aioe.org> <ss53rh$jnj$1@dont-email.me>
<e364aacb-1b8b-4cab-b716-432eaad1bcb1n@googlegroups.com>
<f2af1d8f-dce1-461a-b4c4-e188d825b3ccn@googlegroups.com>
From: Rich...@Damon-Family.org (Richard Damon)
In-Reply-To: <f2af1d8f-dce1-461a-b4c4-e188d825b3ccn@googlegroups.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Lines: 50
Message-ID: <G4KFJ.50950$Q11.38954@fx33.iad>
X-Complaints-To: abuse@easynews.com
Organization: Forte - www.forteinc.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Tue, 18 Jan 2022 20:47:17 -0500
X-Received-Bytes: 3766
X-Original-Bytes: 3633
 by: Richard Damon - Wed, 19 Jan 2022 01:47 UTC

On 1/18/22 10:31 AM, james...@alumni.caltech.edu wrote:
> On Tuesday, January 18, 2022 at 4:16:31 AM UTC-5, Öö Tiib wrote:
>> On Tuesday, 18 January 2022 at 03:07:11 UTC+2, james...@alumni.caltech.edu wrote:
>>> On 1/17/22 5:14 PM, Spyridon Metaxas wrote:
>>>> I have the following problem:
>>>>
>>>> Within the same C executable I need to interact with two
>>>> different modules, A and B, that expose the same standardized API. Which
>>>> module is to be used is something to be decided at run time; for the
>>>> purposes of this discussion, it does not matter how or why.
>>>>
>>>> In order to be able to interact with those modules I need to use
>>>> the include files IA and IAB, respectively, that they provide. I cannot
>>>> include them both, for they both define many of the same data structures
>>>> and function prototypes.
> ...
>>> However, your wording left me wondering whether you might have
>>> incorrectly expressed a problem that's actually harder to deal with. Is
>>> it not just the headers, but also the corresponding object files, that
>>> are incompatible in ways that prevent both of them from being linked
>>> into the same program - do they declare functions or objects with
>>> external linkage that have the same name? If so, you've got a much more
>>> complicated problem to deal with.
>> Yes, the OP as quoted above said that modules "both define many of the
>> same data structures and function prototypes". Most likely "same" there
>> means on several cases "with same name" and not "with same name
>> and definition" ...
>
> I think that's definitely a possibility, but I don't think his description was
> sufficiently clear to guarantee that he's facing this problem. Both headers might
> define the same struct type, and provide two different declarations of the same
> function, in addition to declaring additional identifiers that are unique to each
> module. That's why I asked about it, rather than assuming one answer or the
> other. That would be poor design: the shared features should be declared once
> in a separate header file, with it's own header guards to prevent doubled
> declarations. However, I'd seen worse examples of poor design, so I wouldn't
> rule out that possibility.

And yes, if you have two headers with conflicting declarations for the
same symbol, those headers are incompatible with each other so you can't
use both in the same program.

Sometimes, you just have to live with the fact that something wasn't
built in a way that allows it to be easily reused.

Hopefullly, they have the source for the modules (and the right
permissions) that use those headers, so they can be edited and made
compatible, or they can't use one of the modules.

That's life.

Re: Include files with the same definitions

<sscjlt$495$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20060&group=comp.lang.c#20060

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: vir.camp...@invalid.invalid (Vir Campestris)
Newsgroups: comp.lang.c
Subject: Re: Include files with the same definitions
Date: Thu, 20 Jan 2022 21:19:57 +0000
Organization: A noiseless patient Spider
Lines: 8
Message-ID: <sscjlt$495$2@dont-email.me>
References: <ss4por$ogn$1@gioia.aioe.org> <ss6uil$6hj$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 20 Jan 2022 21:19:57 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="ddd7dabf19e6501ba21ccb3f061ab07b";
logging-data="4389"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+NHjYQP+1jMP7q0YmUaiS21xQXjFLuGYk="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
Cancel-Lock: sha1:t6KC9TVWMzAUVEwxMPWG95Gepmk=
In-Reply-To: <ss6uil$6hj$1@dont-email.me>
Content-Language: en-GB
 by: Vir Campestris - Thu, 20 Jan 2022 21:19 UTC

On 18/01/2022 17:49, Bonita Montero wrote:
> That's easy to solve in C++ with inheritance.

In C++ we could include the two .h files within namespaces.

But this isn't C++, so he's got to live within the language he's using.

Andy

Re: Include files with the same definitions

<ssd0ls$pj0$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20063&group=comp.lang.c#20063

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: Include files with the same definitions
Date: Thu, 20 Jan 2022 17:01:45 -0800
Organization: A noiseless patient Spider
Lines: 62
Message-ID: <ssd0ls$pj0$1@dont-email.me>
References: <ss4por$ogn$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 21 Jan 2022 01:01:49 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="ffc47bf876c6fa695886c334e1d88c91";
logging-data="26208"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+3sZA4VX6Rhh3FBDQpDMlnifaJZhXeBqU="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:8OsoeAzOVOFdPU+kcDXcHR4xl0c=
In-Reply-To: <ss4por$ogn$1@gioia.aioe.org>
Content-Language: en-US
 by: Chris M. Thomasson - Fri, 21 Jan 2022 01:01 UTC

On 1/17/2022 2:14 PM, Spyridon Metaxas wrote:
> I have the following problem:
>
> Within the same C executable I need to interact with two
> different modules, A and B, that expose the same standardized API. Which
> module is to be used is something to be decided at run time; for the
> purposes of this discussion, it does not matter how or why.
>
> In order to be able to interact with those modules I need to use
> the include files IA and IAB, respectively, that they provide. I cannot
> include them both, for they both define many of the same data structures
> and function prototypes. However, because of proprietary extensions, each
> defines stuff that is not present in the other. The thing is, at run time
> I will need to be able to use such extensions: when the program is run I
> will know whether A or B is to be used, and selecting what extension to
> use will be easy.
>
> The bottom line, I need to include both IA and IB at compile
> time, but doing so would result in compile time errors.
>
> How can one deal with this situation? I guess one could create a
> new include file IC containing the stuff common to IA and IB, plus their
> differences. However, that is a horrible hack fraught with danger, for,
> among other things, there is no guarantee that bits that differ between
> IA and IB will be compatible.
>
> There has to be a better, more elegant way to deal with this.
>

One pattern is something akin to:

common.h
impl_0.h
impl_1.h
impl.h

impl.h can select what impl_n.h header to import based on some sort of
macro. common.h is common to the various impl_n's... Also, think of
something really simple like:

void foo_version_0(void)
{

}

void foo_version_1(void)
{

}

void foo_version_2(void)
{

}

// API

#define foo_version foo_version_1

Cheap, and can work. There are many other ways to do these types of
things in C...

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor