• 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: trouble using tgmath
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: trouble using tgmath


  • Subject: Re: trouble using tgmath
  • From: Nathan Vander Wilt <email@hidden>
  • Date: Thu, 1 Oct 2009 11:27:13 -0700

On Oct 1, 2009, at 1:42 AM, Jean-Daniel Dupas wrote:
Le 1 oct. 2009 à 06:06, Nathan Vander Wilt a écrit :

I am trying to use <tgmath.h> to reduce casting while using CGFloat, as recommended: http://www.omnigroup.com/mailman/archive/macosx-dev/2009-June/062331.html

But it's not working as I expect. For example, this code is giving me trouble when compiled for 64-bit:
// CGFloat zoomLevel; (is an ivar)
CGFloat scale = pow(2.0f, -zoomLevel);

Unless I change the function call to pow(2.0f, -(float)zoomLevel), I get "warning: implicit conversion shortens 64-bit value into a 32-bit value" when compiling for 64-bit.

Since the second parameter to pow is a double in the original version, the double version of pow should be used, according to http://www.opengroup.org/onlinepubs/9699919799/basedefs/tgmath.h.html
The macros in <tgmath.h> look like they would make that happen.


I tried something much simpler:
__TGMATH_REAL(1.0, fabs);

But even this gives an implicit conversion warning, on all of gcc 4.0, gcc 4.2, llvm-gcc 4.2!

Why is this happening? Am I totally confused as to how tgmath should be working?


I filled a radar some times ago about this. This warning is about a call in the expanded form of the _expression_.
The expanded macro (which is awful) contains a call to pow(), a call to powf(), a call to powl(), and other variants for complex types. These call are not present in the resulting object as they are stripped done by the compiler, but GCC (spuriously) warns about conversion that would append in these stripped calls.

Ah, that makes sense, even if it is unfortunate.

That said, this issue is fixed in GCC-4.2 on Snow Leopard.

Thanks for pointing this out — I had not tried that yet. It looks like i686-apple-darwin10/4.2.1/include/tgmath.h has a number of casts that the i686-apple-darwin9 version doesn't. Since I don't want to mess with replacing system headers or including copies in my project, I'll just keep using the math.h double versions and casting the results when necessary. One more reason I'm eager to develop for 10.6+ only!

thanks much,
-natevw

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Re: trouble using tgmath (From: Jean-Daniel Dupas <email@hidden>)

  • Prev by Date: Re: XCODE: Problem compiling first Hello World App
  • Next by Date: Re: Stripping
  • Previous by thread: Re: trouble using tgmath
  • Next by thread: Re: IB plug-in for iphone
  • Index(es):
    • Date
    • Thread