QueryCAT Logo
Search 5,000,000+ questions and answers.

Frequently Asked Questions

Why can't I pass a char ** to a function which expects a const char **?

ANSI/ISO Standard C
You can use a pointer-to-T (for any type T) where a pointer-to-const-T is expected. However, the rule (an explicit exception) which permits slight mismatches in qualified pointer types is not applied recursively, but only at the top level. (const char ** is pointer-to-pointer-to-const-char, and the exception therefore does not apply.) The reason that you cannot assign a char ** value to a const char ** pointer is somewhat obscure.

What's the difference between ''char const *p'' and ''char * const p''?

Infrequently Asked Questions in comp.lang.c
One '' '' character. There are some trivial differences having to do with the distinction between a pointer to a constant, and a constant pointer, but since you can cast either to a (char *) it hardly matters. Can I declare main as void, to shut off these annoying ''main returns no value'' messages? (I'm calling exit(), so main doesn't return.) Certainly. You can also declare it as double.

Why can't I convert a char ** to a const char **?

Tech Talk about C++ and C Issues / Comeau C++ and C FAQ
Why can't I convert a char * to a const char *&? The most common response/solution we've seen offered with respect to this issue is that the person with this problem should just use a cast. Unfortunately, there is normally no additional explanation of the matter. So, that's not helpful in understanding the matter. Worse, it can even be considered harmful advice. The second most common response is a blunt "because", but that doesn't help any either.

What's the difference between const char *p, char const *p, and char * const p?

Declarations and Initializations
Build the declaration up incrementally, using typedefs: typedef char *pc; /* pointer to char */ typedef pc fpc(); /* function returning pointer to char */ typedef fpc *pfpc; /* pointer to above */ typedef pfpc fpfpc(); /* function returning... */ typedef fpfpc *pfpfpc; /* pointer to... */ pfpfpc a[N]; /* array of... */ Use the cdecl program, which turns English into C and vice versa.

Why is there a const after some function names?

Tech Talk about C++ and C Issues / Comeau C++ and C FAQ
What is the mutable keyword? Let's see how these questions apply to the following snippet: class xyz { int x; int y; mutable int z; // ... public: static void staticMemFunc(); void definedElsewhere() const; // ... void foo() { x = 99; } int getx() { return x; } int gety() const { return y; } void bar() const { z = -99; } }; void global(int); We know that in effect, the member functions really are: class xyz { // ..

Is defining member function const necessary?

FAQ on C/C++/Unix by Roseanne Zhang, Java Programmer Certifi...
Ah, yes. If a member function does not change the data members of the class, it shouldbe defined const. See the following sample code and read the comments. Take the const for function printMe() to see error. #include<cstdio> class TA { public: void printMe() const; }; void TA::printMe() const { printf("print class TA\n"); } // o cannot be changed by display void display(const TA& o) { // since o is const // you can only invoke const member function o.

Why can't I use static and const together?

FAQ for the microsoft.public.languages.csharp newsgroup
All constants declarations are implicitly static, and the C# specification states that the (redundant) inclusion of the static modifier is prohibited. I believe this is to avoid the confusion which could occur if a reader were to see two constants, one declared static and one not - they could easily assume that the difference in specification implied a difference in semantics.

Can const function modify mutable data member in C++?

FAQ on C/C++/Unix by Roseanne Zhang, Java Programmer Certifi...
See the following code.

What's the relationship between a return-by-reference and a const member function?

Const correctness, C++ FAQ Lite
If you want to return a member of your this object by reference from an inspector method, you should return it using reference-to-const, that is, const X&. The good news is that the compiler will often catch you if you get this wrong.

What is a char?

jGuru: I18N FAQ Home Page
While the char type is basic to the Java language, many programmers stumble over Unicode escapes, values and conversions. The first definition should...

How can I make a keyboard input function that allows you to bring up the CHAR menu (or MATH, etc)?

Frequently Asked Questions
I really need a routine like InputStr given above, but which is able to bring up the CHAR dialog. However, I am not able to make such routine by myself... I received a lot of such questions. These questions are usually asked by newbie programmers, but the answer is quite advanced. Although I don't like to present advanced routines as-is without a lot of necessary explanations, I am requested to do so.

If you can't modify string literals, why aren't they defined as being arrays of const characters?

ANSI/ISO Standard C
One reason is that so very much code contains lines like char *p = "Hello, world!"; which are not necessarily incorrect. These lines would suffer the diagnostic messages, but it's really any later attempt to modify what p points to which would be problems.

Does "const Fred* p" mean that *p can't change?

Const correctness, C++ FAQ Lite
quot;const Fred* p" means that the Fred can't be changed via pointer p, but there might be other ways to get at the object without going through a const (such as an aliased non-const pointer such as a Fred*). For example, if you have two pointers "const Fred* p" and "Fred* q" that point to the same Fred object (aliasing), pointer q can be used to change the Fred object but pointer p cannot.

I can't make my function keys work properly with TNOS under X ?

TNOS Installation
The function key problem with TNOS under X has to do with the fact that the terminfo entry for xterm is seriously broken in many distributions (I know it is in Slackware through at least 1.2.0). Following is an "xterm.tic" souce file for my hacked version that restores fkey functionality. Run it through tic to generate the new database file, and the problem should be solved in xterms (or rxvts) opened thereafter. BTW -- this problem drove me nuts for almost a month.

Why doesn't the %CHAR built-in function work with numeric values?

Frequently Asked Questions
Under the initial release of OS/400 Version 4, Release 2, the %CHAR built-in function was introduced. However, the function, as designed, only converted DATE values to character values. This proved to be too restrictive a use for this function. In OS/400 V4R4 IBM will added function to %CHAR allowing it to convert all forms of non-character data to character. In that release %CHAR works with numeric values. D Amount 7P 2 Inz(123.
More Questions >>

© Copyright 2007-2013 QueryCAT
About • Webmasters • Contact