• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: sprintf and 64-bit integers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sprintf and 64-bit integers


  • Subject: Re: sprintf and 64-bit integers
  • From: "email@hidden" <email@hidden>
  • Date: Sun, 13 Sep 2009 20:10:34 +0200

On Sun, Sep 13, 2009 at 8:01 PM, Bill Bumgarner <email@hidden> wrote:
> On Sep 13, 2009, at 10:59 AM, email@hidden wrote:
> I'm updating my code for Snow Leopard and ran into this problem. The
>>
>> app crashes at this line:
>>
>> sprintf(str, "%d", val);
>>
>> where val is a CFIndex. According to the string programming guide here...
>>
>>
>> http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html
>>
>> ...I need to cast my CFIndex to long and replace the %d format
>> specifier to %ld. I tried that but still got the crash. So I kept
>> trying with all the format specifiers in the book, declaring my
>> variable a NSInteger, unsigned int, etc, but no matter what the app
>> kept crashing. The only that that actually worked was %lx, but then I
>> get the numbers all wrong. It seems that sprintf only accepts 32-bit
>> integers. Is this correct? If so, what's the workaround? I'm compiling
>> for both 10.5 and 10.6. Advice appreciated, thanks.
>
> You are off in the weeds.
>
> There is nothing about a value conversion that could cause a crash.  Wrong
> value? Sure.  But not a crash.  Thus, the formatting string is *not* causing
> a crash.
>
> The problem is almost assuredly that 'str' is pointing to garbage,
> uninitialized or otherwise wrong.
>
> Post the code for how str is created.
>
> b.bum

Sorry, str is simply created like this:

char str[10];
sprintf(str, "%d", val);
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: sprintf and 64-bit integers
      • From: Clark Cox <email@hidden>
    • Re: sprintf and 64-bit integers
      • From: Steve Christensen <email@hidden>
References: 
 >sprintf and 64-bit integers (From: "email@hidden" <email@hidden>)
 >Re: sprintf and 64-bit integers (From: Bill Bumgarner <email@hidden>)

  • Prev by Date: Re: sprintf and 64-bit integers
  • Next by Date: Re: sprintf and 64-bit integers
  • Previous by thread: Re: sprintf and 64-bit integers
  • Next by thread: Re: sprintf and 64-bit integers
  • Index(es):
    • Date
    • Thread