Hi,
I don't understand the idea behind the error in the following code...
int foo(const char **p) { return 0; }
int main(int argc, char **argv)
{
foo(argv);
return 0;
}
thx in adv.
Przemek Drochomirecki 6 1276
przemek drochomirecki wrote: Hi,
I don't understand the idea behind the error in the following code...
int foo(const char **p) { return 0; }
int main(int argc, char **argv) { foo(argv); return 0; }
The types don't match. foo takes a pointer to pointer to const char, but you
pass a pointer to pointer to non-const char.
Rolf Magnus wrote: przemek drochomirecki wrote:
Hi,
I don't understand the idea behind the error in the following code...
int foo(const char **p) { return 0; }
int main(int argc, char **argv) { foo(argv); return 0; }
The types don't match. foo takes a pointer to pointer to const char, but you pass a pointer to pointer to non-const char.
I know that types don't match, but...still don't know why...:)
int foo(char* const* x) { return 0; }
int main(int argc, char **argv)
{
foo(argv);
return 0;
}
Here everything is OK...
Thx, anyway.
Przemek Drochomirecki
przemek drochomirecki wrote: [...] I know that types don't match, but...still don't know why...:)
It's actually explained in the FAQ. See section 18.
V
On Sat, 18 Jun 2005 01:43:04 +0400, przemek drochomirecki
<dr*****@nospam.hyene.com> wrote: Hi,
I don't understand the idea behind the error in the following code...
int foo(const char **p) { return 0; }
int main(int argc, char **argv) { foo(argv); return 0; }
thx in adv.
Przemek Drochomirecki
Please refer to http://www.parashift.com/c++-faq-lit...html#faq-18.17
--
Maxim Yegorushkin
Rolf Magnus wrote: przemek drochomirecki wrote:
Hi,
I don't understand the idea behind the error in the following code...
int foo(const char **p) { return 0; }
int main(int argc, char **argv) { foo(argv); return 0; }
The types don't match. foo takes a pointer to pointer to const char, but you pass a pointer to pointer to non-const char.
....which of course will compile without a problem. It's always
acceptable to pass non-const types when const types are declared. It's
the opposite situation, passing const types as non-const parameters
that the compiler will complain about. But clearly that is not a
problem in this code.
In fact, there is no error in the sample code - a fact which could well
explain the original poster's difficulty in understanding the error.
Greg
* Greg: Rolf Magnus wrote: przemek drochomirecki wrote:
Hi,
I don't understand the idea behind the error in the following code...
int foo(const char **p) { return 0; }
int main(int argc, char **argv) { foo(argv); return 0; }
The types don't match. foo takes a pointer to pointer to const char, but you pass a pointer to pointer to non-const char.
In fact, there is no error in the sample code - a fact which could well explain the original poster's difficulty in understanding the error.
In fact the code is invalid.
The reason it is invalid is that doing what the code attempts to allows
treating a const object as a non-const one, without a cast.
As Victor wrote elsewhere in this thread, see the FAQ.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: jimjim |
last post by:
Hello,
My question concerns as to how a pointer is passed by reference as a
function argument. The following is from code taken from the MICO
implementation of the CORBA specification.
in...
|
by: news.comcast.giganews.com |
last post by:
I have a web page that pops up a new window with a form in it, then when the
user clicks the submit button in the new window, it submits to the
originating window and the new window closes.
This...
|
by: Ike |
last post by:
Anyone have any idea why the following would work on Netscape 7.x but not
MSIE ? Thanks, Ike
<input type=button onClick="recalc()" value="Recalc Form">
..
..
..
<SCRIPT...
|
by: PengYu.UT |
last post by:
Hi,
I find I have to declare a function like "int f(void);", if the
function should not accept any arguments. If I declare with "int f();"
instead, the compiler won't give any error if I call...
|
by: Doug Lind |
last post by:
Hi all,
I have seen a number of posts re: the BinaryFormatter version
incompatibility but nothing on how to recover from it. In my case, I want
the exception to trigger an alternate behaviour...
|
by: bb |
last post by:
Hi,
Class Test {
public:
Test() { cout << "Hello from Test" << endl; }
~Test() { cout << "Bye from Test" << endl; }
};
int main(int argc, char** argv) {
|
by: john |
last post by:
Hello,
Supposed sizeof(short) == 2 and sizeof(int) == 4 and argument passing in
a stack.
When doing:
int i1; int i2;
printf("%d %d", i1, i2); // OK. 2 arg of size 4
|
by: Agile |
last post by:
I have a simple function that takes variable argument list, the sample
code
is below:
func1( char* a, ...)
{
va_list arg_list;
va_start(arg_list,a);
// do something with arg_list
|
by: Andrew Poulos |
last post by:
Say I have this
foo = function() {
// blah
};
bar = fuction(fnName) {
/* If fnName equalled "foo"
* How do I test that foo, as a function,
* exists and then, if it exists, call it?
|
by: lorlarz |
last post by:
In the code sample below, how are arguments a legitimate
argument to Array.slice?
Function.prototype.bind = function(){
var fn = this, args = Array.prototype.slice.call(arguments), object =...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
|
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: 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: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |