HP C A.06.05 Reference Manual
Data Types and Declarations
Declarations
Chapter 336
New Declaration Features
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.
Caveats
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. When specifying
declarations within code in the HP C/ANSI C compiler, do not expect the same behavior in HP
aC++. For example:
for(int i = 0; i < j; i ++) int i;
Note the lack of a new block opening for the for statement. The C++ compiler accepts this
form, with warnings, but the C compiler does not. The difference in the way the stack is
handled causes the difference in behavior.
Previously, the C compiler did not emit the source file information for the global typedefs. To
correct this, use -y option along with -g when debug info is generated. You can generate debug
information by compiling with +objdebug.
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);}
}