login
Header Space

 
 

Re: [PATCH 2/2] Replace literal STRLEN_ #defines in refs.h with compiler evaluated expressions

Score:
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Junio C Hamano <gitster@...>
Cc: Andy Parkins <andyparkins@...>, <git@...>
Date: Saturday, September 29, 2007 - 2:15 pm

On Sat, 29 Sep 2007, Junio C Hamano wrote:

Gcc does, yes.

HOWEVER.

Using "strlen()" may be optimized at compile-time, but it still ends up 
resulting in illegal C code if the constant needs to be a constant in the 
semantic sense.

IOW, the "sizeof()" trick can be portably used for things like array 
declarations etc. But strlen() cannot. Ie

	char array[sizeof("hello")-1];

is legal in non-function scope, but doing the same with "strlen()" is not.

(That said, gcc has been known to accept bad C code, and will in fact 
accept this one too!)

		Linus
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: [PATCH 2/2] Replace literal STRLEN_ #defines in refs.h w..., Linus Torvalds, (Sat Sep 29, 2:15 pm)
speck-geostationary