|
From: | Eric Blake |
Subject: | Re: PATH_MAX on the Hurd |
Date: | Fri, 05 Aug 2011 17:25:10 -0600 |
User-agent: | Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.18) Gecko/20110621 Fedora/3.1.11-1.fc14 Lightning/1.0b3pre Mnenhy/0.8.3 Thunderbird/3.1.11 |
On 08/05/2011 05:19 PM, Paul Eggert wrote:
On 08/05/2011 03:33 PM, Bruno Haible wrote:int a = PATH_MAX; Shouldn't this be: static int a[PATH_MAX];Maybe. Or possibly: enum { a = PATH_MAX }; Are there cases when these three declarations don't all succeed and don't all fail?Oh yes. :-) "int a = PATH_MAX;" would allow a float PATH_MAX, which presumably you'd rather reject. "static int a[PATH_MAX];" might warn you about an array too large if PATH_MAX == SIZE_MAX; I'd make it "static char a[PATH_MAX];". "enum { a = PATH_MAX };" won't work if PATH_MAX exceeds INT_MAX, and also it doesn't check that PATH_MAX is positive; these problems are both fixable, but since the intended use of PATH_MAX is likely array sizes, the array's probably your best bet.
What if we go with the array approach, but without risking overallocation problems? Would this work for a single-byte array:
static char a[PATH_MAX / PATH_MAX]; or is it worth considering the constant context in bit field width: struct s { int a : PATH_MAX / PATH_MAX; } s1; -- Eric Blake address@hidden +1-801-349-2682 Libvirt virtualization library http://libvirt.org
[Prev in Thread] | Current Thread | [Next in Thread] |