Where does it say that?Quote:
Originally Posted by maxorator
The Unix man pages.Quote:
What do you mean by "man"?
Printable View
Where does it say that?Quote:
Originally Posted by maxorator
The Unix man pages.Quote:
What do you mean by "man"?
I can use tolower() when I only include <stdio.h>.Quote:
Originally Posted by CornedBee
I don't use UNIX so I don't know about it's man pages.
On every compiler that exists? Every compiler that might be written?Quote:
Originally Posted by maxorator
The standard is what counts.
So you are saying that <stdio.h> is not a standard header?
No. He's saying that you got it wrong twice. tolower() is defined in <ctype> whether you like it or not. If your compiler implementation has <ctype> included in <stdio.h>, fine. Other implementations may not.
You mean <ctype.h>, right? :)
On UNIX (or Linux, or Cygwin -- an implementation of bash for Windows), you can generally typeQuote:
I don't use UNIX so I don't know about it's man pages.
and get information about that function. There are man pages for programs, functions, system calls, etc, divided into 7 sections by type. (For example, printf() has two man pages, for the program and for the function. To access the man page for the function, type man 3 printf.)Code:$ man function
> You mean <ctype.h>, right?
Yeah. an oversight. Or <cctype> and <cstdio> for all that matters. The point tough being that an implementation is free to decide on how it integrates the several headers. On my implementation #include <iterator> is all I need to use std::string. But that doesn't make it right.
Well you never answered the first question I posed to you (I'll post an answer soon) but here's another one anyway:
What is the difference (in functionality) between a, b, and c?Code:const char * a;
char const * b;
char * const c;
I can honestly say that I don't know...
Well on the first you create a pointer to a const char. You promise you will not alter the value of a. It is also the only way to create a pointer with the address of a const object.
The second is the same as the first. It's using one of the shady syntaxes of C++; the const qualifier after the type.
On the third you create a const pointer to char. You promise you are not going to alter the pointer itself. That is you cannot make it point to something else other than what it was initialized with.
When you come across situations like this, just remember to read them backwards.Quote:
Originally Posted by maxorator
const char * a;
"a is a pointer to a character that is constant"
char const * b;
"b is a pointer to a constant character"
char * const c;
"c is a constant pointer to a character"
These have to do with:
* Whether or not you can change the address the pointer contains (i.e. where the pointer is pointing), and
* Whether or not you can change the contents of the memory the pointer is pointing at.
a and b are identical, with a being the "normal" syntax and b being an alternative; the pointer is not constant (so you could modify the pointer to point to a new area of memory) but the character(s) that it points to ARE constant. For example:
a = &x; // This is legal, because you change where a points to (the address that a holds)
*a = 'A'; // This is illegal because you may not change the contents of the character/string it points to.
c is the opposite -- you cannot change the address that c holds (the pointer is constant) but you CAN modify the memory at that address:
c = &x; // Illegal, you're trying to change the address that c holds.
c[10] = 'C'; // Legal, you can use c to modify the memory it points to.
You can also do one other kind of pointer:
const char * const d;
"d is a constant pointer to a character that is constant"
In that case, you may not alter the pointer OR the memory it points to.
What's wrong with this?
Code:const char **x;
Tricky. :) Took me a awhile. But I didn't cheat.
A char** is not actually a pointer to pointer to char. But instead an array of pointers to char. (as we know from one of the main signatures; main(int argc, char **argv)). Being const means the definition needs to be initialized. Const objectsneed to be initialized at the point of declaration. In your example it wasn't.
A char** is absolutely a pointer to pointer to char. That pointer to a pointer to a char can be pointing at an array of pointers to char, but there is nothing that says it has to.
Also, I think that x can be initialized later, so your second point is wrong as well.
I don't know the exact details, but you can't have a const pointer to a pointer. Perhaps someone can explain why.