CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,867

    logf macro in math.h

    Code:
    #include <math.h>
    
    void SomeFunc()
    {
          float_t winlen   = 4;
          float_t rayparam = 48./512. * winlen;
    
          float dfwvnorm = expf ( (logf(2.0)/rayparam) * (winlen+2) ); // <-- compiler error if I use 'logf' but not if I use 'log'
    }
    I'm trying to build libaubio using VC++8. There's a function that essentially boils down to the above, once I've allowed for a couple of #defines (EXP and LOG, respectively).

    If I use (log(2.0)/rayparam) my compiler seems happy. But if I use (logf(2.0)/rayparam) (which was originally intended in the code) the compiler complains with error C2143: syntax error : missing ')' before ';'. And yet from looking at math.h, logf is defined everywhere that expf is defined. AFAICT they're defined as functions for 64-bit compiles and as macros for 32-bit (mine's 32-bit). Can anyone suggest a reason why the compiler is happy to accept the expf macro but not logf?


    [Edit...] Amazingly, I've discovered a bug in math.h. the macro for logf incorrectly has a semicolon at the end - i.e

    #define logf(x) ((float)log((double)(x)));
    Currently I'm using VC2005 Professional but previously I'd been using VC2005 Express. I've just looked in the Express version's copy of math.h and that doesn't have the problem!
    Last edited by John E; January 1st, 2011 at 12:24 PM.
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  2. #2
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,244

    Re: logf macro in math.h

    Quote Originally Posted by John E View Post

    [Edit...] Amazingly, I've discovered a bug in math.h. the macro for logf incorrectly has a semicolon at the end - i.e

    Code:
    #define logf(x) ((float)log((double)(x)));
    Currently I'm using VC2005 Professional but previously I'd been using VC2005 Express. I've just looked in the Express version's copy of math.h and that doesn't have the problem!
    Hi John,
    I have searched in all MATH.H from my computer (VC6.0/2005/2008/2010) and did not found any logf macro as you described.
    Just
    Code:
    #define logf(x)     ((float)log((double)(x)))
    with no semicolon.

    Are you sure that yours isn't from onother third party library or was not modified by mistake?
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  3. #3
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,867

    Re: logf macro in math.h

    Invariably I add an annotation to a 3rd party file if I modify it so I don't think that's the problem. It's more likely that you've installed a service pack which I haven't got (in fact, I don't think I've installed any service packs at all yet for VS2005).
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  4. #4
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,244

    Re: logf macro in math.h

    Indeed, I've installed service packs as well as SDK updates.
    I will verify ASAP on a "clean" install.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  5. #5
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,867

    Re: logf macro in math.h

    I have the Professional edition (on CD) and the Express edition which I downloaded. Only the Professional edition seems to have the problem. It has two copies of math.h (which strangely, aren't the same size) but both copies seem to be affected.
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  6. #6
    Join Date
    Apr 2008
    Posts
    118

    Re: logf macro in math.h

    Good spot; well done. Get the service pack to fix it.

    http://connect.microsoft.com/VisualS...ling-semicolon

  7. #7
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,244

    Re: logf macro in math.h

    Well then, problem is solved.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  8. #8
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,867

    Re: logf macro in math.h

    Must get around to installing that service pack..!
    "A problem well stated is a problem half solved.” - Charles F. Kettering

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured