Warning meaning.

M

mdh

....snip...


Since it never deals with numbers greater than 1, it avoids all
possibilities of overflow. Also works for all numerical types for
*s and *t.


thanks Chuck...that's what I like about it.
 
B

Barry Schwarz

mdh said:
int main (int argc, const char * argv[])

There's your problem. Should be:

int main(int argc, char *argv[])

instead.

Thank you Pete..
I am beginning to understand the difference in terms of "type of
memory"..(.as per RH.) ..for a char array.

Perhaps you are but it has nothing to do with the problem at hand. In
you declaration of main, you stated that argv "could be considered as"
an array of pointers (we know it is actually a char**) and that each
pointer in the array would point to a constant char. You then passed
argv[1] to a function as an argument that did not agree to treat the
character pointed to as constant. This is what your compiler is
complaining about. The const qualifier that applies to *argv[1] does
not apply to the object pointed to by parameter s of your function.
This would allow the function to legally alter *s but you said
*argv[1] (which is the same object) cannot be modified. The compiler
is pointing out the inconsistency.

If you had cast the argument to an unqualified char*, the compiler
would not complain (actually the compiler can issue any diagnostic it
feels like but that is a different issue). It is only if your
function then attempted to modify *s that the type of memory would be
significant. If the character were actually stored in read only
memory, your hardware/operating system would prevent you from
completing the modification. If not, chances are the modification
would succeed but your code would have entered the realm of undefined
behavior.


Remove del for email
 
M

mdh

Thank you Pete..
I am beginning to understand the difference in terms of "type of
memory"..(.as per RH.) ..for a char array.


In you declaration of main, you stated that argv "could be considered as"
an array of pointers (we know it is actually a char**) and that each
pointer in the array would point to a constant char. You then passed
argv[1] to a function as an argument that did not agree to treat the
character pointed to as constant. This is what your compiler is
complaining about. The const qualifier that applies to *argv[1] does
not apply to the object pointed to by parameter s of your function.
This would allow the function to legally alter *s but you said
*argv[1] (which is the same object) cannot be modified. The compiler
is pointing out the inconsistency.

If you had cast the argument to an unqualified char*, the compiler
would not complain .................snip............ It is only if your
function then attempted to modify *s that the type of memory would be
significant.


Thank you Barry.. I believe I see what is being emphasized.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top