473,388 Members | 1,309 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

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_addr[1];

I still get the same warning.

Cheers,
Chris Peters

Jun 27 '08 #1
2 1886
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
Jun 27 '08 #2
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_addr[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:
http://www.silverfrost.com/11/ftn95/overview.asp

Zivjeli,
--
The only really happy folk are married women and single men.
H. L. Mencken
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Sony Antony | last post by:
I have the following simple program in Solaris Forte compiler 5.4 producing the warning. Though it produces the warning, it works fine as expected. This has been compiling fine without any...
36
by: Dmitriy Iassenev | last post by:
hi, I found an interesting thing in operator behaviour in C++ : int i=1; printf("%d",i++ + i++); I think the value of the expression "i++ + i++" _must_ be 3, but all the compilers I tested...
20
by: News | last post by:
I'm new to c and gcc. I was wondering if anyone can point me to a web page or book that has a list of the warning messages and their meanings. Are the warnings the same no matter what compiler...
6
by: Chad | last post by:
I'm not too sure if the question would fall under comp.lang.c or some kind of compiler newsgroup. I'm going to ask anyhow. Given the following: #include <stdio.h> int main(void) { int a =...
24
by: asdf | last post by:
I got a warning from the following statement: fprintf(point_file, "CONTOUR\nCLOSE\n%d\n", curve.size()); warning: format '%d' expects type 'int', but argument 3 has type 'size_t' should I...
11
by: Charles Sullivan | last post by:
I have a number of functions, e.g.: int funct1( int arg1, int arg2, int arg3 ); int funct2( int arg1, int arg2, int arg3 ); int funct3( int arg1, int arg2, int arg3 ); that are called via...
3
by: gil | last post by:
Hi, I'm trying to find the best way to work with compiler warnings. I'd like to remove *all* warnings from the code, and playing around with the warning level, I've noticed that compiling with...
17
by: matevzb | last post by:
I've ran into some fishy code that, at first glance, is buggy, but it seems to work correctly and none of the compilers I've tried (five so far, on various systems) gives any warnings. The code:...
1
by: raylopez99 | last post by:
The below did not set off my compiler, perhaps because I set the warnings to a higher (less nag) level. Strange. FYI, no question being asked. RL double d2030;
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.