The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-17-2006
Registered User
 

Join Date: May 2006
Posts: 95
Stumble this Post!
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;
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 08-17-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 3,849
Stumble this Post!
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.
Reply With Quote
  #3 (permalink)  
Old 09-01-2006
Registered User
 

Join Date: May 2006
Posts: 95
Stumble this Post!
so the only solution to write something like a compartible solution is to write:

printf("res=%" PRIdMAX ".%"PRIdMAX " \n", res.quot,res.rem);
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:16 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0