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. Calling Conventions Demystified

Calling Conventions Demystified

Scheduled Pinned Locked Moved C / C++ / MFC
help
2 Posts 2 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.
  • C Offline
    C Offline
    Cmania
    wrote on last edited by
    #1

    I must say "thnx" to the writer of article "Calling Conventions Demysified". It is such a good article, i mean im a student n i feel it is must for every c programmer. But im confused with what was written in first few lines : "the value is returned in EAX register." I mean no problem with basic types but how this statement fits fine for structures like: struct abc { int x; float y; }; struct abc fun(void) { struct abc x; x.x=0; x.y=1; return x; }

    Spread wat u Know!

    D 1 Reply Last reply
    0
    • C Cmania

      I must say "thnx" to the writer of article "Calling Conventions Demysified". It is such a good article, i mean im a student n i feel it is must for every c programmer. But im confused with what was written in first few lines : "the value is returned in EAX register." I mean no problem with basic types but how this statement fits fine for structures like: struct abc { int x; float y; }; struct abc fun(void) { struct abc x; x.x=0; x.y=1; return x; }

      Spread wat u Know!

      D Offline
      D Offline
      Daniel Grunwald
      wrote on last edited by
      #2

      Returning things that don't fit into a register have a special rule in all calling conventions that use a register to return values. One possible solution some calling conventions use is that the caller reserves the memory for the return value and passes a pointer to it to the called function as a hidden parameter. So your example would be compiled like:

      struct abc
      {
      int x;
      float y;
      };
      void fun(struct abc *result)
      {
      struct abc x;
      x.x=0;
      x.y=1;
      *result = x;
      }

      An optimizing compiler might assign directly to result->x and result->y.

      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