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. Using / accessing function pointer declaration externally

Using / accessing function pointer declaration externally

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestionannouncement
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.
  • V Offline
    V Offline
    Vaclav_
    wrote on last edited by
    #1

    OK, this is really simple question, with example code to boot. The function pointer declaration is this void (*gpf_isr)(void) = (0UL); It is used by this function void UOTGHS_Handler( void ) { if (gpf_isr) gpf_isr(); } and I access it like so extern void (*gpf_isr)(void); then I assign my local poiter / version of the function gpf_isr = ( object ) . UTOGHS_Handler; The silly question why this also get pass the compiler , no errors extern void (*gpf_isr)(void) = (0UL); The pointer gets reassigned , but ...

    CPalliniC L 2 Replies Last reply
    0
    • V Vaclav_

      OK, this is really simple question, with example code to boot. The function pointer declaration is this void (*gpf_isr)(void) = (0UL); It is used by this function void UOTGHS_Handler( void ) { if (gpf_isr) gpf_isr(); } and I access it like so extern void (*gpf_isr)(void); then I assign my local poiter / version of the function gpf_isr = ( object ) . UTOGHS_Handler; The silly question why this also get pass the compiler , no errors extern void (*gpf_isr)(void) = (0UL); The pointer gets reassigned , but ...

      CPalliniC Online
      CPalliniC Online
      CPallini
      wrote on last edited by
      #2

      See, for instance How to define extern variable along with declaration?[^]

      In testa che avete, signor di Ceprano?

      V 1 Reply Last reply
      0
      • V Vaclav_

        OK, this is really simple question, with example code to boot. The function pointer declaration is this void (*gpf_isr)(void) = (0UL); It is used by this function void UOTGHS_Handler( void ) { if (gpf_isr) gpf_isr(); } and I access it like so extern void (*gpf_isr)(void); then I assign my local poiter / version of the function gpf_isr = ( object ) . UTOGHS_Handler; The silly question why this also get pass the compiler , no errors extern void (*gpf_isr)(void) = (0UL); The pointer gets reassigned , but ...

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        The key point here is the extern qualifier. That states that the variable can be referred to from any module in the final linked executable, but only one instance of it will actually exist.

        1 Reply Last reply
        0
        • CPalliniC CPallini

          See, for instance How to define extern variable along with declaration?[^]

          V Offline
          V Offline
          Vaclav_
          wrote on last edited by
          #4

          That is pretty clear that defining the variable is OK, but if optioned GCC will give a warning. Kind like deleting a file and being ask "are you sure?" Thanks .

          CPalliniC 1 Reply Last reply
          0
          • V Vaclav_

            That is pretty clear that defining the variable is OK, but if optioned GCC will give a warning. Kind like deleting a file and being ask "are you sure?" Thanks .

            CPalliniC Online
            CPalliniC Online
            CPallini
            wrote on last edited by
            #5

            Yes. You may find (on the web) folks arguing that warning is not legitimate. In a clean implementation you don't qualify with extern the variable in the source file wherein you define it.

            In testa che avete, signor di Ceprano?

            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