Am 05.08.2011 um 00:37 schrieb [email protected]:

> Reuti writes:
> 
>> yes, it's a known bug. The backspace should rub out an already printed 0:
>> 
>> http://arc.liv.ac.uk/pipermail/gridengine-users/2010-March/029490.html
> 
> Ok, here's my take on this
> 
> Problem is that the formatting string needs to accommodate both digits and
> the string INFINITY
> 
> You thus use
> 
> %d%s
> 
> and you print a "" if it's not INFINITY but have to use a backspace, to
> bin the 0 already printed, if it is.
> 
> #define FORMAT_LIMIT(x) (x==RLIMIT_INFINITY)?0:x,
> (x==RLIMIT_INFINITY)?"\bINFINITY":""
> 
> Given that you already rewrite the limit, (x), why not rewrite it as:
> 
> #define FORMAT_LIMIT(x) (x==RLIMIT_INFINITY)?"INFINITY":x
> 
> but define the format string to be used based on the value of (x) as well
> 
> #define FORMAT_LIMIT_STR(x)
> (x==RLIMIT_INFINITY)?"%s":"%some_value_for_various_int_sizes"
> 
> So further down the code, this would be the equivalent (I have left the
> original #define and my suggestions in here for inspection)
> 
> #if defined(NECSX4) || defined(NECSX5) || defined(NETBSD_ALPHA) ||
> defined(NETBSD_X86_64) || defined(NETBSD_SPARC64)
> #  define limit_fmt "%ld%s"
> #  define FORMAT_LIMIT_STR(x) (x==RLIMIT_INFINITY)?"%s":"%ld"
> #elif defined(IRIX) || defined(HPUX) || defined(DARWIN) ||
> defined(FREEBSD) || defined(NETBSD) || defined(INTERIX)
> #  define limit_fmt "%lld%s"
> #  define FORMAT_LIMIT_STR(x) (x==RLIMIT_INFINITY)?"%s":"%lld"
> #elif (defined(LINUX) && defined(TARGET_32BIT))
> #  define limit_fmt "%llu%s"
> #  define FORMAT_LIMIT_STR(x) (x==RLIMIT_INFINITY)?"%s":"%llu"
> #elif defined(ALPHA) || defined(SOLARIS) || defined(LINUX)
> #  define limit_fmt "%lu%s"
> #  define FORMAT_LIMIT_STR(x) (x==RLIMIT_INFINITY)?"%s":"%lu"
> #else
> #  define limit_fmt "%d%s"
> #  define FORMAT_LIMIT_STR(x) (x==RLIMIT_INFINITY)?"%s":"%d"
> #endif
> 
> and then replace instances of limit_fmt with FORMAT_LIMIT_STR(x)
> 
> Can anyone see a problem with that?

I have two remarks:

The result of the ? operator must have a fixed type: either an integer or a 
string (better: pointer to a string).

Also the format string will have to be assembled beforehand (by string 
operations in C), as it will be contructed at runtime in your version, not at 
compile time like with the #define statement (it changes the source at compile 
time).

You can check the generated preprocessor output with: gcc -C -E foobar.c

-- Reuti


> If not, and I will certainly give it a go locally, I'll create
> a patch.
> 
> Kevin
> 
> -- 
> Kevin M. Buckley                                  Room:  CO327
> School of Engineering and                         Phone: +64 4 463 5971
> Computer Science
> Victoria University of Wellington
> New Zealand
> 
> _______________________________________________
> users mailing list
> [email protected]
> https://gridengine.org/mailman/listinfo/users


_______________________________________________
users mailing list
[email protected]
https://gridengine.org/mailman/listinfo/users

Reply via email to