Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. __FUNCTION__ Macro

__FUNCTION__ Macro

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++delphilinux
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    ROK_RShadow
    wrote on last edited by
    #1

    I was currently reading an article in my linux mag about the wonderful uses of the assert function. I personally use this function and variations of it a lot. My question arises when I caught a side bar of the article about some preprocessor macros. The sidebar explains how assert is so great because of the __LINE__ and __FILE__ macros. However it also explains two useful macros that are available under the GNU C compiler. __FUNCTION__ and __PRETTY_FUNCTION__. The first being for C compilers it returns the functions name. Since C++ mangles function names do to overloading the second returns the full function name (i.e. "void CMyClass::myfunc(int, double)" ). However these do not seem to be available under Microsoft's or Borland's compiler, and a long search through MSDN doesn't reveal anything similar. Is there a way to produce similar output with the MS compiler?

    A J 2 Replies Last reply
    0
    • R ROK_RShadow

      I was currently reading an article in my linux mag about the wonderful uses of the assert function. I personally use this function and variations of it a lot. My question arises when I caught a side bar of the article about some preprocessor macros. The sidebar explains how assert is so great because of the __LINE__ and __FILE__ macros. However it also explains two useful macros that are available under the GNU C compiler. __FUNCTION__ and __PRETTY_FUNCTION__. The first being for C compilers it returns the functions name. Since C++ mangles function names do to overloading the second returns the full function name (i.e. "void CMyClass::myfunc(int, double)" ). However these do not seem to be available under Microsoft's or Borland's compiler, and a long search through MSDN doesn't reveal anything similar. Is there a way to produce similar output with the MS compiler?

      A Offline
      A Offline
      Andrew Walker
      wrote on last edited by
      #2

      A good place to start is current_function.hpp in the boost library. Boost tends to be a good place to start for information and patterns which work around differences in compilers.

      #ifndef BOOST_CURRENT_FUNCTION_HPP_INCLUDED
      #define BOOST_CURRENT_FUNCTION_HPP_INCLUDED
      
      #if _MSC_VER >= 1020
      #pragma once
      #endif
      
      //
      //  boost/current_function.hpp - BOOST_CURRENT_FUNCTION
      //
      //  Copyright (c) 2002 Peter Dimov and Multi Media Ltd.
      //
      //  Permission to copy, use, modify, sell and distribute this software
      //  is granted provided this copyright notice appears in all copies.
      //  This software is provided "as is" without express or implied
      //  warranty, and with no claim as to its suitability for any purpose.
      //
      //  http://www.boost.org/libs/utility/current_function.html
      //
      
      namespace boost
      {
      
      namespace detail
      {
      
      inline void current_function_helper()
      {
      
      #if defined(__GNUC__) || (defined(__MWERKS__) && (__MWERKS__ >= 0x3000))
      
      # define BOOST_CURRENT_FUNCTION __PRETTY_FUNCTION__
      
      #elif defined(__FUNCSIG__)
      
      # define BOOST_CURRENT_FUNCTION __FUNCSIG__
      
      #elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x550)
      
      # define BOOST_CURRENT_FUNCTION __FUNC__
      
      #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901)
      
      # define BOOST_CURRENT_FUNCTION __func__
      
      #else
      
      # define BOOST_CURRENT_FUNCTION "(unknown)"
      
      #endif
      
      }
      
      } // namespace detail
      
      } // namespace boost
      
      #endif // #ifndef BOOST_CURRENT_FUNCTION_HPP_INCLUDED
      

      If you can keep you head when all about you Are losing theirs and blaming it on you; If you can dream - and not make dreams your master; If you can think - and not make thoughts you aim; Yours is the Earth and everything that's in it. Rudyard Kipling

      1 Reply Last reply
      0
      • R ROK_RShadow

        I was currently reading an article in my linux mag about the wonderful uses of the assert function. I personally use this function and variations of it a lot. My question arises when I caught a side bar of the article about some preprocessor macros. The sidebar explains how assert is so great because of the __LINE__ and __FILE__ macros. However it also explains two useful macros that are available under the GNU C compiler. __FUNCTION__ and __PRETTY_FUNCTION__. The first being for C compilers it returns the functions name. Since C++ mangles function names do to overloading the second returns the full function name (i.e. "void CMyClass::myfunc(int, double)" ). However these do not seem to be available under Microsoft's or Borland's compiler, and a long search through MSDN doesn't reveal anything similar. Is there a way to produce similar output with the MS compiler?

        J Offline
        J Offline
        Jim A Johnson
        wrote on last edited by
        #3

        __FUNCTION__ is available in VS.NET; it returns the undecorated name of the function.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups