Thread (4 messages) flat view 4 messages, 4 authors, 2016-06-15

Re: [PATCH v4] gc: call "prune --expire 2.weeks.ago" by default

From: Wincent Colaiuta <hidden>
Date: 2016-06-15 22:44:22

El 13/3/2008, a las 0:39, Junio C Hamano escribió:
Ah,...

But C language rules haven't changed in such a way that it  
guarantees B to
be evaluated before A when you write "A >= B", have it?

So at least I think you would need something like this if you go that
route:

 		if (strcmp(value, "now")) {
               	unsigned long now = approxidate("now");
               	if (approxidate(value) >= now)
				return error("Invalid %s: '%s'", var, value);
			...
		}

Are you sure that that alternative provides any guarantees about  
evaluation order either? (I'm not a compiler expert, nor am I  
consulting a copy of the standard; but I don't think it does.)

In order to enforce evaluation in the required order I think it might  
have to be something like this:

	if (strcmp(value, "now")) {
		unsigned long now;
		if ((now = approxidate("now")) &&
		    approxidate(value) >= now)
			return error("Invalid %s: '%s'", var, value);
		...
	}

ie. the && operator guarantees left to right evaluation order, and  
since approxidate always returns a non-zero ulong the second  
expression (after the &&) will always be evaluated.

Cheers,
Wincent
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help