Re: Need for const in function argument list

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Sunday, 26 March 2006 16:27 samaye, Steve Graegert alekhiit:

> Because the format (the string to display) is provided as a constant
> expression and it is not being modified:
> 	printf("%s\n", "abc");
> 	printf("%s\n", mystring);
> In both cases the format argument is a constant string.

Why, the following works as well:

#include "stdio.h"
void main(void)
{
	char s[10] = "\n%s\n\n";
	printf(s, "hello");
}

Here s is not a const char *. It is a variable char *. That actually compiled 
and executed. So probably it's only because the printf *function* does not 
change the value (and *should* not change the value during parsing, I 
presume).

-- 

Tux #395953 resides at http://samvit.org
playing with KDE 3.51 on SUSE Linux 10.0
$ date [] CCE +2006-03-26 W12-7 UTC+0530
-
: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Assembler]     [Git]     [Kernel List]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [C Programming]     [Yosemite Campsites]     [Yosemite News]     [GCC Help]

  Powered by Linux