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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. A pointer of variable or a function?

A pointer of variable or a function?

Scheduled Pinned Locked Moved C / C++ / MFC
data-structuresquestion
5 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.
  • F Offline
    F Offline
    fitatc
    wrote on last edited by
    #1

    There is a macro _countof, the define is

    template <typename _CountofType, size_t _SizeOfArray>
    char (*__countof_helper(UNALIGNED _CountofType (&_Array)[_SizeOfArray]))[_SizeOfArray];
    #define _countof(_Array) sizeof(*__countof_helper(_Array))

    It confuse me that __countof_helper is a very weird pointer. At first glance, I thought it is a pointer of array, but, how can an variable can have an "()" suffix???

    L 1 Reply Last reply
    0
    • F fitatc

      There is a macro _countof, the define is

      template <typename _CountofType, size_t _SizeOfArray>
      char (*__countof_helper(UNALIGNED _CountofType (&_Array)[_SizeOfArray]))[_SizeOfArray];
      #define _countof(_Array) sizeof(*__countof_helper(_Array))

      It confuse me that __countof_helper is a very weird pointer. At first glance, I thought it is a pointer of array, but, how can an variable can have an "()" suffix???

      L Offline
      L Offline
      loyal ginger
      wrote on last edited by
      #2

      It's a template of a function pointer array.

      F 1 Reply Last reply
      0
      • L loyal ginger

        It's a template of a function pointer array.

        F Offline
        F Offline
        fitatc
        wrote on last edited by
        #3

        shouldn't a function pointer's size be 4? how can a sizeof(*funcPtrArray(param)) turn out to be some relation with ReturnValTypeSize

        modified on Sunday, January 31, 2010 9:20 PM

        G 1 Reply Last reply
        0
        • F fitatc

          shouldn't a function pointer's size be 4? how can a sizeof(*funcPtrArray(param)) turn out to be some relation with ReturnValTypeSize

          modified on Sunday, January 31, 2010 9:20 PM

          G Offline
          G Offline
          Graham Breach
          wrote on last edited by
          #4

          It declares a function that takes an array and returns an array of char with the same number of elements. The sizeof operator acts on the returned array to give the number of elements.

          F 1 Reply Last reply
          0
          • G Graham Breach

            It declares a function that takes an array and returns an array of char with the same number of elements. The sizeof operator acts on the returned array to give the number of elements.

            F Offline
            F Offline
            fitatc
            wrote on last edited by
            #5

            This makes sense. Thank you very much :)

            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