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. Can define a function with same name and signature?

Can define a function with same name and signature?

Scheduled Pinned Locked Moved C / C++ / MFC
6 Posts 6 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.
  • S Offline
    S Offline
    sandeep manzhi
    wrote on last edited by
    #1

    In C++ this concept are overloading and overriding Can i use this concept in C?

    D L L B 4 Replies Last reply
    0
    • S sandeep manzhi

      In C++ this concept are overloading and overriding Can i use this concept in C?

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      What would the purpose be?

      "One man's wage rise is another man's price increase." - Harold Wilson

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

      1 Reply Last reply
      0
      • S sandeep manzhi

        In C++ this concept are overloading and overriding Can i use this concept in C?

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

        Same as what?

        1 Reply Last reply
        0
        • S sandeep manzhi

          In C++ this concept are overloading and overriding Can i use this concept in C?

          L Offline
          L Offline
          leon de boer
          wrote on last edited by
          #4

          Yes you can but if you want to do it statically it has to be done via compiler directives and smart macros and it's used by embedded programmers in some specific situations. It is not something we encourage to use like the C++ feature but there are times it is the only way to achieve what is needed. It has been improved and is portable and easy if your compiler accepts the C11 standard word "_Generic". Here is a reasonable link on it Rob's Programming Blog: C11 - Generic Selections[^] You can see the general form of the macro which provides the overloading

          #define acos(X) _Generic((X), \
          long double complex: cacosl, \
          double complex: cacos, \
          float complex: cacosf, \
          long double: acosl, \
          float: acosf, \
          default: acos \
          )(X)

          As the C community is still one of the larger programming languages the standard has been altered over time. In time order the main standards are C87, C90, C99, C11. Microsoft and Visual Studio has been one of the slowest compilers to include the new standards. Visual studio 2013 was the first version to cover most of C99 but it has been available in GCC and many micro-controller C compilers for many years.

          In vino veritas

          CPalliniC 1 Reply Last reply
          0
          • L leon de boer

            Yes you can but if you want to do it statically it has to be done via compiler directives and smart macros and it's used by embedded programmers in some specific situations. It is not something we encourage to use like the C++ feature but there are times it is the only way to achieve what is needed. It has been improved and is portable and easy if your compiler accepts the C11 standard word "_Generic". Here is a reasonable link on it Rob's Programming Blog: C11 - Generic Selections[^] You can see the general form of the macro which provides the overloading

            #define acos(X) _Generic((X), \
            long double complex: cacosl, \
            double complex: cacos, \
            float complex: cacosf, \
            long double: acosl, \
            float: acosf, \
            default: acos \
            )(X)

            As the C community is still one of the larger programming languages the standard has been altered over time. In time order the main standards are C87, C90, C99, C11. Microsoft and Visual Studio has been one of the slowest compilers to include the new standards. Visual studio 2013 was the first version to cover most of C99 but it has been available in GCC and many micro-controller C compilers for many years.

            In vino veritas

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

            Wow, never heard about that, before.

            In testa che avete, signor di Ceprano?

            1 Reply Last reply
            0
            • S sandeep manzhi

              In C++ this concept are overloading and overriding Can i use this concept in C?

              B Offline
              B Offline
              Bram van Kampen
              wrote on last edited by
              #6

              Well, Nearly per Definition you can Not use a C Compiler to compile CPP! You do not understand where it all came from, but I'll ex[plain. 'C' was created by Brian Kernigan and Dennis Ritchie as a High Level Language, with the flexibility of Assembler. It has a straight forward flat language structure, needing a very simple symbol table. (The Symbol Table is a database used by the Compiler, to keep track of what symbolic value is stored where) This database would not allow for items like 'MyStruct.MyMember'.Instead, it kept a separate Database of Structure Names. When Brian Stroustrep started CPP, it was initially a 'PreCompiler' which would write a 'C' acceptable set of variable names. For Intance: void MyStruct::MyFunct(int,char,int) would be translated into something like 'FnMyStruct_MyFunct_int_char_int__void' and then let the 'C' Compiler do it's Job. That worked of a kind, but, what if one also were to write a 'C' function: 'FnMyStruct_MyFunct_int_char_int__void(int Param)' Unlikely, but, a potential problem. Brian Stroustrep had to use symbols and characters acceptable to the 'C' language. When proper CPP Compilers appeared at the scene, the decoration became more flexible. For Instance: 'FnMyStruct?MyFunct??int_char_int???void' Such a name cannot be passed as a 'C' Name. (Note: I do not state that the scheme here is actually used, it is just an illustration to explain the point of how a CPP Compiler generates different code compared to a 'C' compiler) A CPP compiler can compile 'C' Code. The otherway around, a 'C' Compiler accepting CPP Code is never going to happen, for the reasons stated above. Now, As others have Asked: what is your problem! Perhaps you want to Include a 'C' Module in your 'CPP Project' :)

              Bram van Kampen

              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