By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,159 Members | 882 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,159 IT Pros & Developers. It's quick & easy.

C Compiler error?

P: 2
a[4] = 0; a[3 = 0; a[2] = 0; a[1] = 0; a[0] = 0;

are the results from the printf() in the following program using an old Borland C++ (V4.5) compiler.

#include <stdio.h>
int a[] = {0, 1, 2, 3, 4};
int main( ) {
int *p;
for (p = a+4; p >= a; p--)
printf ("a[%d] = %d;\t", (p-a), a[p-a]);
return 0;

When I assigned an integer i = p-a; in the 'for loop' then replaced (p-a) and a[p-a] with i, and a[i], respectively - the program prints OKAY!

When I stepped through the above code using Borland C debugger, I got this message : "Conversion might loose significant digits." when I evaluate a[p-a]!

Then again, if I replace the above printf() with

printf ("%d;\t", a[p-a]);

then I got what were expected: 4; 3; 2; 1; 0
BUT the debugger still generated the above "Conversion..." message when I evaluated a[p-a]!

So, Is this a case of compiler error / or is there a subtle concept in C language that I miss?

Nov 5 '06 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.