Strange compiler warnings

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chris Peters

    Strange compiler warnings

    Hi,

    I'm using some Fortran 77 code together with C, and the compiler is giving
    me some strange warnings. Can anyone help explain what's going on? The
    code runs just fine.


    1)
    Fortran code

    integer m_testa(10)
    common /testa/m_testa


    C code

    extern struct testa
    {
    int m_testa[10];
    };

    gives warning useless keyword or type name in empty declaration


    ==


    2)

    Fortran code

    integer*8 m_addr (20)
    common /testb/ m_addr


    C code

    extern struct testb
    {
    long long int m_addr[20]; // to contain any variable address
    };
    ....

    int value; // in the line below, my_addr is the address of an integer
    variable

    value = *(int*)testb_.m _addr[1];

    gives warning cast to pointer from integer of different size


    If I change the code to
    long long int value;
    value = *(long long int*)testb_.m_a ddr[1];

    I still get the same warning.

    Cheers,
    Chris Peters

  • Eric Sosman

    #2
    Re: Strange compiler warnings

    Chris Peters wrote:
    Hi,
    >
    I'm using some Fortran 77 code together with C, and the compiler is giving
    me some strange warnings. Can anyone help explain what's going on? The
    code runs just fine.
    >
    >
    1)
    Fortran code
    >
    integer m_testa(10)
    common /testa/m_testa
    >
    >
    C code
    >
    extern struct testa
    {
    int m_testa[10];
    };
    >
    gives warning useless keyword or type name in empty declaration
    >
    You probably want

    extern struct {
    int m_testa[10];
    } testa;
    ==
    >
    >
    2)
    >
    Fortran code
    >
    integer*8 m_addr (20)
    common /testb/ m_addr
    >
    >
    C code
    >
    extern struct testb
    {
    long long int m_addr[20]; // to contain any variable address
    };
    ...
    >
    int value; // in the line below, my_addr is the address of an integer
    variable
    >
    value = *(int*)testb_.m _addr[1];
    >
    gives warning cast to pointer from integer of different size
    I'm not sure what you're trying to do here, so instead of
    offering a correction I'll just try to explain what's happening:

    - First off, there's the problem that `testb_' isn't
    declared anywhere. I'll assume that you've declared it as
    a variable of type `struct testb'.

    - The fragment `testb_.m_addr' is a reference to the
    `m_addr' element of this `testb_' variable. Assuming the
    variable is in fact a `struct testb', the element is an
    array of twenty `long long int' values.

    - Working outward, `testb_.m_addr[1]' is the second of
    those values (element [0] is the first, element [19] is the
    twentieth and last).

    - `(int*)testb_.m _addr[1]' fetches the `long long int'
    value from the array and converts it to an `int*' pointer.
    This is what provokes the compiler, presumably because a `long
    long int' has more bits than an `int*' does, so there's a risk
    of losing information in the conversion. (Strictly speaking,
    the risk exists even if the pointer and the integer have the
    same width; conversions between pointers and integers are
    allowed, but the outcome is implementation-defined and need
    not be meaningful.)

    - Finally, `*(int*)testb_. m_addr[1]' uses the converted
    pointer to access an `int' somewhere in memory, at a location
    that depends on the value stored in the second array element:
    1LL or 42LL or -123456789LL or whatever.

    This is probably not what you were intending to do, but
    I don't know just where what you wrote departs from what you
    meant.
    >
    If I change the code to
    long long int value;
    value = *(long long int*)testb_.m_a ddr[1];
    >
    I still get the same warning.
    Presumably because a `long long int' is wider than a
    `long long int*', and once again the compiler alerts you to
    the possible loss of information.

    --
    Eric.Sosman@sun .com

    Comment

    • Ron Ford

      #3
      Re: Strange compiler warnings

      On Thu, 12 Jun 2008 21:39:45 +0100, Chris Peters posted:
      Hi,
      >
      I'm using some Fortran 77 code together with C, and the compiler is giving
      me some strange warnings. Can anyone help explain what's going on? The
      code runs just fine.
      >
      >
      1)
      Fortran code
      >
      integer m_testa(10)
      common /testa/m_testa
      >
      >
      C code
      >
      extern struct testa
      {
      int m_testa[10];
      };
      >
      gives warning useless keyword or type name in empty declaration
      >
      >
      ==
      >
      >
      2)
      >
      Fortran code
      >
      integer*8 m_addr (20)
      common /testb/ m_addr
      >
      >
      C code
      >
      extern struct testb
      {
      long long int m_addr[20]; // to contain any variable address
      };
      ...
      >
      int value; // in the line below, my_addr is the address of an integer
      variable
      >
      value = *(int*)testb_.m _addr[1];
      >
      gives warning cast to pointer from integer of different size
      >
      >
      If I change the code to
      long long int value;
      value = *(long long int*)testb_.m_a ddr[1];
      >
      I still get the same warning.
      Fortran 77 is what John Travolta may have encountered were he not on the
      disco floor. To combine that with the difficulties attending to long long
      is the equivalent of asking his Italian friends to program. Let me take a
      couple stabs at what the warnings may have been:

      1) warning 5212: polyester is too hot in the long, long summertime.

      2) warning 3414: has Microsoft even been founded yet?

      3 warning 2784: you can take disco classes, but you were three left feet
      with Susan tonight.

      Update your capabilities with your common C extension:
      Home to FTN95: Fortran for Windows. Free personal edition. .NET, Win32, x64, 64-bit.


      Zivjeli,
      --
      The only really happy folk are married women and single men.
      H. L. Mencken

      Comment

      Working...