![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| printf | mirusnet | Shell Programming and Scripting | 4 | 01-23-2008 06:09 AM |
| printf | arunviswanath | High Level Programming | 2 | 09-19-2007 06:31 PM |
| printf command in ksh | cin2000 | Shell Programming and Scripting | 1 | 12-21-2005 10:48 AM |
| awk printf problem | krishna | UNIX for Advanced & Expert Users | 6 | 11-18-2003 07:59 PM |
| printf command | FIRE | Shell Programming and Scripting | 2 | 08-07-2002 11:18 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
printf and imaxdif_t
i was playing with maxint stuff when i found that i could not find a propper way to do
a printf() auf a imaxdiv_t. since nobody seems to use it google found nothing. i tried to find a PRIxy code but no success. example: #include <stdio.h> #include <inttypes.h> int main() { imaxdiv_t res; res=imaxdiv(1234,10); printf("res=%" PRIdMAX "\n",res); // printf("res=%lld\n",res); return 0; } gcc -Wall imaxdiv.c warning: format ‘%lld’ expects type ‘long long int’, but argument 2 has type ‘imaxdiv_t’ is there any why to printf() without warning ? what is the way the inventor had in mind ? Note: imaxdit_t is actualy a struct typedef struct { long long int quot; /* Quotient. */ long long int rem; /* Remainder. */ } imaxdiv_t; |
| Forum Sponsor | ||
|
|
|
|||
|
imaxdiv is the same function (idea) as div - it just uses the largest possible integer on the platform. Use lldiv if this function gives you heartburn.
You don't print the result struct, you print either the remainder or the quotient. imaxdiv_t is platform specific - it returns the largest available integer on your platform, and that is what gcc is complaining about, because it is not necessarily long long. If sizeof says quot is a long long on your platform, then just cast. I'm thinking it may not be. The idea behind imaxdiv was to provide a "portable largest possible integer range implementation of div for any platform." It is part of C99. Last edited by jim mcnamara; 08-17-2006 at 06:40 AM. |