Calling Convention - Window Programming - Lecture Slides, Slides of Windows Programming

Calling convention, Element, Implementation, Storage Class Modifiers, Initialization, Register Storage Class, Static Storage Class, Extern Storage Class, Stack are the terms you can learn in this lecture and few others as well.

Typology: Slides

2011/2012

Uploaded on 11/06/2012

parasad
parasad 🇮🇳

4.5

(56)

131 documents

1 / 46

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Windows Programming
Lecture 07
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e

Partial preview of the text

Download Calling Convention - Window Programming - Lecture Slides and more Slides Windows Programming in PDF only on Docsity!

Windows Programming

Lecture 07

Calling convention

__cdecl

This is the default calling convention for C programs. Because the stack is cleaned up by the caller. The __cdecl calling convention creates larger executables than __stdcall, because it requires each function call to include stack cleanup code.

__cdecl

The following list shows the implementation of this calling convention.

Element Implementation Argument-passing orderRight to left Stack-maintenance responsibility

Calling function pops the arguments from the stack Name-decoration convention Underscore character (_) is prefixed to names Case-translation convention No case translation performed

__stdcall

The __stdcall calling convention is used to call Win32 API functions. The callee cleans the stack.

__stdcall

Element Implementation Argument-passing order Right to left

Argument-passing convention By value, unless a pointer or reference type is passed. Stack-maintenance responsibility Called function pops its own arguments from the stack

The following list shows the implementation of this calling convention.

__stdcall

  • Functions declared using the __stdcall modifier return values the same way as functions declared using __cdecl.
  • In the following example, use of __ stdcall results in all WINAPI function types being handled as a standard call:

#define WINAPI __stdcall

_// Example of the _stdcall keyword

__pascal

The callee cleans the stack.

Argument-passing order: Right to left

auto - storage class

The auto storage class specifier lets you define a variable with automatic storage; its use and storage is restricted to the current block. The storage class keyword auto is optional in a data declaration. It is not permitted in a parameter declaration. A variable having the auto storage class specifier must be declared within a block. It cannot be used for file scope declarations.

auto - storage class

Because automatic variables require storage only while they are actually being used, defining variables with the auto storage class can decrease the amount of memory required to run a program. However, having many large automatic objects may cause you to run out of stack space.

auto - storage class

Initialization

You can initialize any auto variable except parameters. If you do not initialize an automatic object, its value is indeterminate. If you provide an initial value, the expression representing the initial value can be any valid C expression. For structure and union members, the initial value must be a valid constant expression if an initializer list is used. The object is then set to that initial value each time the program block that contains the object's definition is entered.

register - Storage Class

  • The register storage class specifier indicates to the compiler that a heavily used variable (such as a loop control variable) within a block scope data definition or a parameter declaration should be allocated a register to minimize access time.
  • It is equivalent to the auto storage class except that the compiler places the object, if possible, into a machine register for faster access.

register - Storage Class

  • An object having the register storage class specifier must be defined within a block or declared as a parameter to a function.
  • The following example lines define automatic storage duration objects using the register storage class specifier: register int score1 = 0, score2 = 0; register unsigned char code = 'A'; register int *element = &order[0];

register - Storage Class

Initialization You can initialize any register object except parameters. If you do not initialize an automatic object, its value is indeterminate. If you provide an initial value, the expression representing the initial value can be any valid C expression. For structure and union members, the initial value must be a valid constant expression if an initializer list is used. The object is then set to that initial value each time the program block that contains the object's definition is entered.