473,387 Members | 1,536 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,387 software developers and data experts.

strange warnings passing int* to const int*

hi,

i'm using "gcc version 3.3.3 (Debian)" to compile the program pasted below.
I get the two warnings you can see in the remarks. The second warning is
perfectly OK for me, but the first one I don't understand.

Isn't the "const int *" construct in the signature of func1 a hint for the
user, that func1 doesn't modify **arg? Why then is it dangerous to
pass an alterable argmument?

thanks for your help!

----------------------------------------------------
void func1(const int *arg[]) { }

void func2(int *arg[]) { }

int main(argc)
{
const int *ary1[10];
int *ary2[10];

func1(ary1);
func1(ary2); // warning: passing arg 1 of `func1' from incompatible pointer type
func2(ary1); // warning: passing arg 1 of `func2' from incompatible pointer type
func2(ary2);
}
----------------------------------------------------
Nov 14 '05 #1
1 2085

On Fri, 9 Jul 2004, george doubleu wrote:

i'm using "gcc version 3.3.3 (Debian)" to compile the program pasted below.
I get the two warnings you can see in the remarks. The second warning is
perfectly OK for me, but the first one I don't understand.

Isn't the "const int *" construct in the signature of func1 a hint for the
user, that func1 doesn't modify **arg? Why then is it dangerous to
pass an alterable argument?
void func1(const int *arg[]) { }

int *ary2[10];

func1(ary2); // warning: passing arg 1 of `func1'
// from incompatible pointer type

'ary2' is an 'array[10] of pointer to int'. It decays in this context
to a 'pointer to pointer to int'. That is, it is the address of a
'pointer to int'.

'func1' expects a parameter of type 'pointer to pointer to const int'.
That is, it expects the address of a 'pointer to const int'.

'pointer to int' and 'pointer to const int' are two different
types, in C. Pointers to different types are not compatible. Thus
'pointer to (pointer to int)' is not compatible with 'pointer to
(pointer to const int)'. Thus GCC gives you a warning.

How to fix it? See another thread in this newsgroup about
improper const-ifying's leading to type errors (Passing const void*
to free, or some such). Also Google for "const poisoning."
The bottom line is that this kind of error can look bizarre, but
it never occurs in well-written, real-life code, so just accept
it and you'll never see it again. :)

-Arthur
Nov 14 '05 #2

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...
2
by: Naren | last post by:
Hello All, I dont get errors but I get warnings though the code runs fine. Could anyone help me removing these warnings c:\program files\microsoft visual studio\vc98\include\vector(48) : warning...
13
by: Neil Zanella | last post by:
Hello, I wonder whether anyone has ever come across the following g++ compiler error message. I don't recall ever seeing it before. I solved my problem but I am still not sure about what this...
12
by: Charlie Zender | last post by:
Hi, I am unable to compile a large body of code with extremely pedantic compile time checks activate, so that warnings cause errors. With GCC 3.3.1, I do this with gcc -std=c99 -pedantic...
15
by: Walter Dnes (delete the 'z' to get my real address | last post by:
I'm trying to initialize an array of error messages, so that I can print out an error message by using the 'nth string in an array, e.g. printf("%s\n", messages); I'm still hazy on arrays of...
3
by: gaulle | last post by:
i'm a newbie in c. now i 'm learning it.i read a code,and compile it in dev-c++4.9.9.0.it can be compiled and pass.but there are some warnings.while in TC2.0,no any warning.it's why? #include...
10
by: Bernard Liang | last post by:
Consider the following excerpt below, with the included relevant declarations. Firstly, the lines marked with **, ***, **** at the beginning are not supposed to have those stars at the...
28
by: charlie | last post by:
Hi, I found an article on informit.com that talks about C++ casts http://www.informit.com/guides/content.asp?g=cplusplus&seqNum=285&rl=1 The strange thing is the author says the following...
11
by: Christopher Key | last post by:
Hello, Can anyone suggest why gcc (-W -Wall) complains, test.c:22: warning: passing arg 1 of `f' from incompatible pointer type when compiling the following code? Change the declation of f...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.