Loading....
Coupon Accepted Successfully!

 

Ansi And Turbo-C++ Keywords

ANSI C++ has introduced various new keywords according to new characteristics of the language. The following table describes the keywords of both ANSI and Turbo C++:

128577.jpgTable 21.1 Keywords supported by ANSI and Turbo C++

asm

else

namespace

template

auto

enum

new

this

bool

explicit

operator

throw

break

export

private

true

case

extern

protect

try

catch

false

public

typedef

char

float

register

typeid

class

for

reinterpret_cast

typename

const

friend

return

union

const_cast

goto

short

unsigned

continue

if

signed

using

default

inline

sizeof

virtual

delete

int

static

void

do

long

static-cast

volatile

double

main

struct

wchar­_t

dynamic­_ cast

mutable

switch

while

Additional keywords for Turbo C++

cdecl

_ss

_cs

_export

far

_fastcall

huge

interrupt

_loads

near

pascal

_saveregs

_seg

         

The Keyword pascal

The keyword pascal is used to declare a variable or function using a Pascal-style naming convention:

Syntax:

pascal <data definition>;

pascal <function definition>;

In addition, pascal declares Pascal-style parameter-passing conventions when applied to a function header (first parameter pushed first; the called function cleans up the stack).

Examples:

int pascal x;

void pascal show(int x, int y);

 

21.22 Write a program to use pascal keyword and change the calling convention of C++ to pascal style.

#include<iostream.h>

#include<constream.h>

void main()

{

clrscr();

void pascal show (int,int);

int x=2;

show (++x,x);

}

void pascal show (int x, int y)

{

cout<<“\n x=”<<x <<“ y=”<<y;

}

 

OUTPUT

x=3 y=3

 

 

Explanation: We know that in C/C++ the calling convention is from right to left; that is, the right most variable is first pushed in the stack. In order to replace this calling convention style with Pascal style, the keyword pascal can be used. This keyword is given in the prototype declaration and function declarator. When we pass an argument to this function, the calling convention will be from left to right. The calling conventions are described in Chapter 11.

The Keyword cdecl

The keyword cdecl is used to declare a variable or a function in the C-style naming convention and pushes arguments in the stack in C-style parameter-passing conventions.

cdecl <data definition> ;

cdecl <function definition> ;

Example:

int cdecl l x;

void cdecl show(int x, int y);

 

21.23 Write a program to demonstrate the use of cdecl keyword.

#include<iostream.h>

#include<constream.h>

void main()

{

clrscr();

void cdecl show (int,int);

int x=7;

show (++x,x);

}

void cdecl show ( int x, int y)

{

cout<<“\n x=”<<x <<“ y=”<<y;

}

 

OUTPUT

x=8 y=7

 

 

Explanation: The above program is similar to the previous one. Here, the keyword cdecl is used to apply the calling convention of C.





Test Your Skills Now!
Take a Quiz now
Reviewer Name