I'm writing a very simple C program, which begins like this:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int
main( int argc, char **argv ){
// check that the program has been invoked correctly
if( argc < 3 ){
fprintf( stderr, "Usage: find_char <string> <string>.\n" );
exit( EXIT_FAILURE );
}
char const *source = (const) (*++argv);
For the last line, I get the following warning:
main.c:17:3: warning: type defaults to 'int' in type name [enabled by default] char const *source = (const) (*++argv);
I tried:
char const *source = NULL;
source = (const) (*++argv);
but gives the same varning for the second line. What is going on here?
casting to const
amounts to casting to const int
. When type is omitted and only qualified is set, the compiler just assumes int
.
Just remove the (const)
cast. You already did the right thing by declaring the pointed values as const
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.