public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++] anonymous struct linkage
@ 2012-11-22 15:44 LAMOME Julien CS-SI
  2012-11-22 15:49 ` Andrew Haley
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: LAMOME Julien CS-SI @ 2012-11-22 15:44 UTC (permalink / raw)
  To: gcc-help

Hi,
we have a code mixing C++ and Fortran 77. In fortran, we have some COMMON like :
COMMON / DEMOF/VARIABLE
Which are include in fortran source file like this :
#include <demof.include>

We link with C++ code like this :
struct { double variable}demof ;

The problem is : 
Between gcc 4.3 and gcc 4.6, the linkage of demof (in C++) change from global to local. This breaks the link between C++ and fortran.

How can I restore the global linkage in gcc 4.6 ?

Thanks you for your help.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [C++] anonymous struct linkage
  2012-11-22 15:44 [C++] anonymous struct linkage LAMOME Julien CS-SI
@ 2012-11-22 15:49 ` Andrew Haley
  2012-11-22 18:53 ` Ángel González
  2012-11-22 21:03 ` Jonathan Wakely
  2 siblings, 0 replies; 8+ messages in thread
From: Andrew Haley @ 2012-11-22 15:49 UTC (permalink / raw)
  To: LAMOME Julien CS-SI; +Cc: gcc-help

On 11/22/2012 03:44 PM, LAMOME Julien CS-SI wrote:
> Hi,
> we have a code mixing C++ and Fortran 77. In fortran, we have some COMMON like :
> COMMON / DEMOF/VARIABLE
> Which are include in fortran source file like this :
> #include <demof.include>
> 
> We link with C++ code like this :
> struct { double variable}demof ;
> 
> The problem is : 
> Between gcc 4.3 and gcc 4.6, the linkage of demof (in C++) change from global to local. This breaks the link between C++ and fortran.
> 
> How can I restore the global linkage in gcc 4.6 ?

That doesn't sound right.  Please send us example code.

Andrew.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [C++] anonymous struct linkage
  2012-11-22 15:44 [C++] anonymous struct linkage LAMOME Julien CS-SI
  2012-11-22 15:49 ` Andrew Haley
@ 2012-11-22 18:53 ` Ángel González
  2012-11-22 21:03 ` Jonathan Wakely
  2 siblings, 0 replies; 8+ messages in thread
From: Ángel González @ 2012-11-22 18:53 UTC (permalink / raw)
  To: LAMOME Julien CS-SI; +Cc: gcc-help

On 22/11/12 16:44, LAMOME Julien CS-SI wrote:
> Hi,
> we have a code mixing C++ and Fortran 77. In fortran, we have some COMMON like :
> COMMON / DEMOF/VARIABLE
> Which are include in fortran source file like this :
> #include <demof.include>
>
> We link with C++ code like this :
> struct { double variable}demof ;
>
> The problem is : 
> Between gcc 4.3 and gcc 4.6, the linkage of demof (in C++) change from global to local. This breaks the link between C++ and fortran.
>
> How can I restore the global linkage in gcc 4.6 ?
>
> Thanks you for your help.
It's probably not that it doesn't global linkage, but something else
like mangling (extern "C"), not going to the common section (although it
should, __attribute__ ((section ("common"))) ), that you want instead to
refer to it when defined from fortran (extern), etc.

What are you doing, how is it expected to work from each side, and what
are you getting?


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [C++] anonymous struct linkage
  2012-11-22 15:44 [C++] anonymous struct linkage LAMOME Julien CS-SI
  2012-11-22 15:49 ` Andrew Haley
  2012-11-22 18:53 ` Ángel González
@ 2012-11-22 21:03 ` Jonathan Wakely
  2012-11-22 21:06   ` Jonathan Wakely
  2 siblings, 1 reply; 8+ messages in thread
From: Jonathan Wakely @ 2012-11-22 21:03 UTC (permalink / raw)
  To: LAMOME Julien CS-SI; +Cc: gcc-help

On 22 November 2012 15:44, LAMOME Julien CS-SI
<julien.lamome-cs-si@irsn.fr> wrote:
> Hi,
> we have a code mixing C++ and Fortran 77. In fortran, we have some COMMON like :
> COMMON / DEMOF/VARIABLE
> Which are include in fortran source file like this :
> #include <demof.include>
>
> We link with C++ code like this :
> struct { double variable}demof ;
>
> The problem is :
> Between gcc 4.3 and gcc 4.6, the linkage of demof (in C++) change from global to local. This breaks the link between C++ and fortran.
>
> How can I restore the global linkage in gcc 4.6 ?

Give the type a name:

struct D { double variable; } demof;

Problem solved.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [C++] anonymous struct linkage
  2012-11-22 21:03 ` Jonathan Wakely
@ 2012-11-22 21:06   ` Jonathan Wakely
  2012-11-23  7:58     ` LAMOME Julien CS-SI
  0 siblings, 1 reply; 8+ messages in thread
From: Jonathan Wakely @ 2012-11-22 21:06 UTC (permalink / raw)
  To: LAMOME Julien CS-SI; +Cc: gcc-help

On 22 November 2012 21:03, Jonathan Wakely wrote:
> On 22 November 2012 15:44, LAMOME Julien CS-SI
> <julien.lamome-cs-si@irsn.fr> wrote:
>> Hi,
>> we have a code mixing C++ and Fortran 77. In fortran, we have some COMMON like :
>> COMMON / DEMOF/VARIABLE
>> Which are include in fortran source file like this :
>> #include <demof.include>
>>
>> We link with C++ code like this :
>> struct { double variable}demof ;
>>
>> The problem is :
>> Between gcc 4.3 and gcc 4.6, the linkage of demof (in C++) change from global to local. This breaks the link between C++ and fortran.
>>
>> How can I restore the global linkage in gcc 4.6 ?
>
> Give the type a name:
>
> struct D { double variable; } demof;
>
> Problem solved.

Alternatively, give it C language linkage:

extern "C" {
  struct { double d; } demof;
}

^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: [C++] anonymous struct linkage
  2012-11-22 21:06   ` Jonathan Wakely
@ 2012-11-23  7:58     ` LAMOME Julien CS-SI
  2012-11-23  9:37       ` Jonathan Wakely
  2012-11-26 15:49       ` Ángel González
  0 siblings, 2 replies; 8+ messages in thread
From: LAMOME Julien CS-SI @ 2012-11-23  7:58 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: gcc-help

a minimum code to show the problem :
toto.F :
      subroutine toto()
      implicit none
      real*8 variable
      common /demof/variable

         print*,'Fortran variable=',variable
      end

toto.cc: 
#include <iostream>
struct {double variable;}demof;
extern "C" void toto();
int main()
{
	demof.variable=3.14159;
	std::cout<<"C++  variable = "<<demof.variable<<std::endl;
	toto();
	return 0;
}

* Gcc 4.1 give me :
C++  variable = 3.14159
 Fortran variable= 3.14159000000000
* Gcc 4.6 give me:
C++  variable = 3.14159
 Fortran variable= 0.00000000000000

Yours differents solutions work, but I would prefer to use an option to have the old behavior. Because, I have 163 files with anonymous strut to modify. And, each file require special attention because struct are linked, or not, with a COMMON, and COMMON are not necessary include in source, etc.
So, if it isn't possible to use an option, I will have a lot of work now. Else I could modify  progressively.

-----Message d'origine-----
De : Jonathan Wakely [mailto:jwakely.gcc@gmail.com] 
Envoyé : jeudi 22 novembre 2012 22:07
À : LAMOME Julien CS-SI
Cc : gcc-help@gcc.gnu.org
Objet : Re: [C++] anonymous struct linkage

On 22 November 2012 21:03, Jonathan Wakely wrote:
> On 22 November 2012 15:44, LAMOME Julien CS-SI
> <julien.lamome-cs-si@irsn.fr> wrote:
>> Hi,
>> we have a code mixing C++ and Fortran 77. In fortran, we have some COMMON like :
>> COMMON / DEMOF/VARIABLE
>> Which are include in fortran source file like this :
>> #include <demof.include>
>>
>> We link with C++ code like this :
>> struct { double variable}demof ;
>>
>> The problem is :
>> Between gcc 4.3 and gcc 4.6, the linkage of demof (in C++) change from global to local. This breaks the link between C++ and fortran.
>>
>> How can I restore the global linkage in gcc 4.6 ?
>
> Give the type a name:
>
> struct D { double variable; } demof;
>
> Problem solved.

Alternatively, give it C language linkage:

extern "C" {
  struct { double d; } demof;
}

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [C++] anonymous struct linkage
  2012-11-23  7:58     ` LAMOME Julien CS-SI
@ 2012-11-23  9:37       ` Jonathan Wakely
  2012-11-26 15:49       ` Ángel González
  1 sibling, 0 replies; 8+ messages in thread
From: Jonathan Wakely @ 2012-11-23  9:37 UTC (permalink / raw)
  To: LAMOME Julien CS-SI; +Cc: gcc-help

On 23/11/2012, LAMOME Julien CS-SI <julien.lamome-cs-si@irsn.fr> wrote:
> a minimum code to show the problem :
> toto.F :
>       subroutine toto()
>       implicit none
>       real*8 variable
>       common /demof/variable
>
>          print*,'Fortran variable=',variable
>       end
>
> toto.cc:
> #include <iostream>
> struct {double variable;}demof;
> extern "C" void toto();
> int main()
> {
> 	demof.variable=3.14159;
> 	std::cout<<"C++  variable = "<<demof.variable<<std::endl;
> 	toto();
> 	return 0;
> }
>
> * Gcc 4.1 give me :
> C++  variable = 3.14159
>  Fortran variable= 3.14159000000000
> * Gcc 4.6 give me:
> C++  variable = 3.14159
>  Fortran variable= 0.00000000000000
>
> Yours differents solutions work, but I would prefer to use an option to have
> the old behavior. Because, I have 163 files with anonymous strut to modify.
> And, each file require special attention because struct are linked, or not,
> with a COMMON, and COMMON are not necessary include in source, etc.
> So, if it isn't possible to use an option, I will have a lot of work now.
> Else I could modify  progressively.



The old behaviour does not conform to the C++ standard.

I don't think there is any option to restore the old non-conforming behaviour.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [C++] anonymous struct linkage
  2012-11-23  7:58     ` LAMOME Julien CS-SI
  2012-11-23  9:37       ` Jonathan Wakely
@ 2012-11-26 15:49       ` Ángel González
  1 sibling, 0 replies; 8+ messages in thread
From: Ángel González @ 2012-11-26 15:49 UTC (permalink / raw)
  To: LAMOME Julien CS-SI; +Cc: Jonathan Wakely, gcc-help

On 23/11/12 08:57, LAMOME Julien CS-SI wrote:
> Yours differents solutions work, but I would prefer to use an option to have the old behavior. Because, I have 163 files with anonymous strut to modify. And, each file require special attention because struct are linked, or not, with a COMMON, and COMMON are not necessary include in source, etc.
> So, if it isn't possible to use an option, I will have a lot of work now. Else I could modify  progressively.

This will _probably_ perform it for you:
 sed -i 's/^struct/extern "C" struct/' *.cpp

There are a number of assumptions with that, so YMMV, test it, tweak if
needed, etc.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2012-11-26 15:49 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-22 15:44 [C++] anonymous struct linkage LAMOME Julien CS-SI
2012-11-22 15:49 ` Andrew Haley
2012-11-22 18:53 ` Ángel González
2012-11-22 21:03 ` Jonathan Wakely
2012-11-22 21:06   ` Jonathan Wakely
2012-11-23  7:58     ` LAMOME Julien CS-SI
2012-11-23  9:37       ` Jonathan Wakely
2012-11-26 15:49       ` Ángel González

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).