Re: Possible OS incompatibility with __attribute__ 'shared'

Jonathan Wakely via Gcc-help <[email protected]> Mon, 22 Dec 2025 08:40:03 +0000
Newsgroups gmane.comp.gcc.help
Message-ID <CAH6eHdR2+uCrHKSP+-1dnzKd4fvRFxYMFtPb_21APV0hWxMX4Q@mail.gmail.com>
On Sun, 21 Dec 2025, 22:48 , <[email protected]> wrote:

> Basile Starynkevitch <[email protected]> wrote:
> (21/12/2025 21:46)
>
> >On Sun, 2025-12-21 at 21:32 +0000, [email protected] wrote:
> >> Hello. On the web page at
> https://gcc.gnu.org/onlinedocs/gcc-3.3.3/gcc/Variable-Attributes.html
> >>
> >> I found this:
> >> int foo __attribute__((section ("shared"), shared)) = 0;
> >>
> >> I got it to work (using MinGW GCC) in W98, but the same method did not
> work in Windows 7, even when restricted to 32-bit process interactions.
> >
> >
> >Current GCC is 15
> >
> >(the 3.3 one was from 2005)
> >
> >Regards
> >
> >--
> >
>
> Thanks, but that does not answer the question. The compiled code runs on
> BOTH systems. The only difference is that the method described does not
> work on Windows 7, whether the resulting executables are recompiled there
> or not. If it had never worked at all, I'd consider the choice of compiler
> version as relevant.
>
> The question is not about the versions of GCC. It's about the
> compatibility for the method as described, given that it works in one
> Windows OS but not the other. If this puts it beyond the scope of advice on
> GCC, how about some other simple way to share a single variable between
> processes using a hook DLL. I mention that because I'm trying to avopid
> making this an 'XY' problem (a phrase I see a lot on StackOverflow...)
>
> Crow
>

You might need a linker option to make the shared segment work.

Another option is a memory mapped file.

https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2008/h90dkhs0(v=vs.90)?redirectedfrom=MSDN

>