When writing software in POWER C, there are some peculiarities that must be accounted for. POWER C is a programming language from 1986, meaning that its keywords and its syntax are pre C89 / ANSI C, which had been defined as a standard in 1989. In this article I am documenting the things I noticed when writing software in POWER C. This is by far no complete list.
Commenting a single line
| Not working | Working |
| // This is a comment | /* This is a comment */ |
Initializing an array right after declaring it
| Not working | Working |
| int arr[] = { 1,2,3 }; | int arr[]; arr[0] = 1; arr[1] = 2; arr[3] = 3; |
Declaring a variable inside the for statement
| Not working | Working |
| for (int i=0; i<10;i++) { } | int i; for (i=0; i<10;i++) { } |
Declaring a variable as an argument to a function
| Not working | Working |
| int isPrime (unsigned int n) { } | unsigned int n; int isPrime (n) { } |
Explicitly declaring that a function returns no value
| Not working | Working |
| void main (int) | main (int) /* or */ int main(int) /* for a function that returns an integer and takes an integer */ |
Variables of type const
| Not working | Working |
| const int i = 10; const char *str; | int i = 10; /* or: #define INT 10 */ char str*; |
Using free() on a NULL initialized array
| Not working | Working |
| int *arr = NULL; free (arr); /* This will crash the computer */ | int *arr; arr=(int *)malloc(2*sizeof(int)); /* optional */ free (arr); |
Declaring and initializing a string within a function
| Not working | Working |
| int main(void) { char str[] = „Hello World!“; /* illegal assignment */ printf („%s\n“, str); return 0; } | char str[] = „Hello World!“; int main(void) { printf („%s\n“, str); return 0; } |
Format conversion
| Not working | Working |
| printf („float : %*f\n“, 3, 1.2345); printf („%0*d“, 5, 3); printf („int: %+d\n“, i); scanf („Number: %ld“, &n); printf („pointer: %p\n“, p); /* POWER C does not support the e and p conversion types */ | printf (float: %.3f\n“, 1.2345); /* POWER C does not use flags like ‚0‘ */ /* POWER C does not use flags like ‚+‘ */ scanf („Number: %d“, &n); printf („pointer int: %d\n“, p); |
stdlib.h
| Not working | Working |
| #include <stdlib.h> | /* POWER C has separate object files for i.e. free() and malloc(), which the linker will find when referenced */ |