Home arrow Programming Fundamentals arrow System Description and Specification

Language Translator

Hacking Zone

Hacking Tools
Attacking

Configure Windows

Windows Configuration

Novels

Mix Novels

Human Personality

Body Language
System Description and Specification PDF Print E-mail
Written by Hemanshu Patel   
Saturday, 13 October 2007
Article Index
System Description and Specification
Page 2
Page 3
Page 4
Page 5

PRE and POST

These comment headers are assertions associated with subroutines. In C++ they are used to establish the conditions that are expected at the entry and exit points of a function. Before the assertion notation was proposed some programmers used the terms ON ENTRY: and ON EXIT:

The PRE: assertion describes the elements (usually variables and constants) that must be supplied by the caller and the POST: assertion describes the state of computation at the moment the function concludes its execution. Thus, the PRE: and POST: conditions represent the terms of a contract between caller and function, stating that if the caller ensures that the PRE: assertion is true at call time, the function guarantees that the POST: assertion is satisfied at return time. For example, the following function named Swap() exchanges the values in two integer variables.

void Swap( int& var1, int& var2)

// PRE: Assigned var1 && var2

// POST: var1 == var2 && var2 == var1

{

int temp = var1;

var1 = var2;

vat 2 = temp;

return;

}

FCTVAL

This assertion is also used in the context of subroutines to indicate the returned value. In C++ FCTVAL represents the value returned by a function and associated with the function name. Therefore it should not be used to represent variables modified by the function. For example, the following trivial function returns the average of three real numbers passed by the caller.

float Avrg( float num1, float num2, float num3)

// PRE: Assigned num1 && num2 && num3

// num1 + num2 + num3

// POST: FCTVAL == ..........

// 3

{

return ((num1 + num2 + num3) / 3));

}



 
< Prev   Next >
Your Ad Here

Donate us!!

Enter Amount:

RSS socialnet

Add to MyYahoo!
Subscribe in NewsGator Online
Add to Newsburst
Add to Google
Add to My AOL
Add to Pluck
Subscribe in FeedLounge
Add to Windows Live
Add to NetVibes
Subscribe in Rojo
Subscribe in Bloglines
Add to MyMSN
Add to Plusmo for your cellphone
Add to PageFlakes
Add to Technorati
Add to BlinkBits