HPlogo HP C/HP-UX Release Notes for HP-UX 11.01: HP 9000 Computers > Chapter 1 New and Changed Features

Declarations within code

» 

Technical documentation

Complete book in PDF

 » Table of Contents

HP C has added the C9x feature which allows you to declare variables and types inside a block of statements. This also allows declaration of new variables or types, such as expr_1, as shown in the for statement below:

for(expr_1;expr_2;expr_3) statement_1

This new variable or type declared in expr_1 can be used in expr_2, expr_3 and statement_1.

NOTE: The HP C/ANSI C compiler implementation of declarations within code is similar to, but not identical to, the C++ implementation of declarations within code See Chapter 4 “Problem Descriptions and Fixes ” for a description of how HP C uses declarations within code differently than the HP aC++ compiler.

Example

int main()
{
  int i=5,j;

  j=i*i;
  printf(*"%d\n",j);

  int k=j;
  /*This is accepted in the new release of HP C*/

for(struct aa {int a;int b} AA={10,50};AA.a<=AA.b;AA.a++){
     /*This is accepted by the new feature */
     printf("%d\n",AA.a);}
}
© Hewlett-Packard Development Company, L.P.