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. The Lounge
  3. Speaking of C++

Speaking of C++

Scheduled Pinned Locked Moved The Lounge
questionc++
24 Posts 15 Posters 2 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.
  • Richard Andrew x64R Richard Andrew x64

    That's a very interesting point, because I just assumed that C's default convention was stdapi. The reason I assumed that is that when you want to export a function from a C++ DLL, you usually enclose the declaration in extern "C". But I never considered that C's default convention was cdecl. Well played. :)

    The difficult we do right away... ...the impossible takes slightly longer.

    K Offline
    K Offline
    kalberts
    wrote on last edited by
    #21

    extern "C" indicates that C++ name mangling should not be used - just the plain function name, not decorated with the types of the function arguments for overload resolution.

    M 1 Reply Last reply
    0
    • K kalberts

      Quote:

      Windows was from the beginning designed to be programmed in C.

      That is true if you never opened a window before it became 32 bits. The native calling convention of the original 16 bits Windows was the Pascal way of doing it.

      D Offline
      D Offline
      Daniel Pfeffer
      wrote on last edited by
      #22

      1. The Windows SDK was always published first in C. If any ports to other languages occurred (e.g. Borland's Borland Pascal), they were delayed by some months. 2. As my OP said, the calling convention is handled by the C compiler, so unless you are programming in Assembly language, it is irrelevant. I stand by my statement.

      Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.

      1 Reply Last reply
      0
      • Richard Andrew x64R Richard Andrew x64

        What is the theory behind making the default calling convention cdecl? It leads to larger code and it's fundamentally incompatible with OS APIs. What were they thinking?

        The difficult we do right away... ...the impossible takes slightly longer.

        P Offline
        P Offline
        Plamen Dragiyski
        wrote on last edited by
        #23

        C existed during 16 bit period and I am almost sure that RET instruction did not take argument back then. Your computer most likely start in real mode, which is 16 bit, so it is still in use today. I suppose that is why they do not want to change the calling convention. P.S. fastcall prolog is usually optimized (under /O2 or more) to use arguments directly from registers when possible.

        1 Reply Last reply
        0
        • K kalberts

          extern "C" indicates that C++ name mangling should not be used - just the plain function name, not decorated with the types of the function arguments for overload resolution.

          M Offline
          M Offline
          Mark Kruger
          wrote on last edited by
          #24

          Your partly correct, indeed it indicates that C++ name mangling should not be used. But this does not mean plain function names. It's mangling the way c get's mangled. For example a function returning a 32 bit int would be something like function@4 and if u take stdcall c function by a microsoft vc compiler u often get even more mangling on the function name.

          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