Am 05.08.2011 um 02:31 schrieb [email protected]:

>> 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).
> 
> Ooops: yes, of course. Hence the double test and the backspace.
> 
>> Also the format string will have to be assembled beforehand ...
> 
> Again, yes.
> 
> So I should leave the, eg,
> 
> #define limit_fmt "%ld%s"
> 
> in each block but just make it the required int format specifier
> (in this case)
> 
> #define limit_fmt "%ld"
> 
> and then define my format string macro to use that compile time define
> for the int or else to just a "%s".

I don't get what you want to do here. #define is interpreted at compile time. 
You can't change limit_fmt at runtime anywhere.


You are on Solaris, or why you don't like the "%.0d%s" solution? It should work 
with Solaris too as "%.0lu%s" (maybe it's even possible to leave the 0 out, as 
a missing specification is interpreted as zero):

http://download.oracle.com/docs/cd/E19082-01/819-2243/6n4i099ag/index.html


Assembling the format string at runtime means to:

#include <stdio.h>
#include <string.h>
#define FMT(x) (x<0)?"%05d":"%+10d"

int main(void)
{
    char      line[255];
    int       value_int;

    value_int = 42;

    strcpy(line, "The value is = ");
    strcat(line, FMT(value_int));
    strcat(line, "\n");

    printf(line, value_int);


    value_int = -1;

    strcpy(line, "The value is = ");
    strcat(line, FMT(value_int));
    strcat(line, "\n");

    printf(line, value_int);

    return (0);
}

-- Reuti



> Look, the issue is enough of a pain in the arse for me to try and
> resolve it properly, so watch this (back)space!
> 
> 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