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_addr[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.
--
Er*********@sun.com