B
Beej Jorgensen
Bill Cunningham said:They have decided to take me off of klonopin.
That's one nasty-sounding drug; I hope you can do without it.
-Beej
Bill Cunningham said:They have decided to take me off of klonopin.
Bill Cunningham said:No Ben. uh-uh. You're not tricking me on this one. That's c99. Been
there done that.
BTW, do you work for Microsoft?
No Ben. uh-uh. You're not tricking me on this one. That's c99. Been(e) /* foo */ for (int i = 0; i < n; i++)
For some people (and I think Bill is one of them) it solves the problem.
Fair point. I must admit I didn't realise BC was using a conforming
C99 implementation.
[snip]Find a way to quote properly. Do it manually if you have to, or
install OE-QuoteFix (Google it), or use a different newsreader.
Do this before posting again.
Use better names for your variables. The name "i" is commonly used
for a loop index; you're using it for an array, which makes your code
more difficult to read. "j" and "k" are sometimes used secondary loop
indices; "j" is ok, but you're using "k" as a sum.
Here's a version of your program with better names for the variables
and no other changes. I've left all your errors in place. It should
now be easier to see at least some of them.
#include <stdio.h>
#define __STRICT_ANSI__
int main(void)
{
int arr[4], i, sum;
sum = 0;
for (i = 0; sum < 4; ++i)
sum = sum + arr;
printf("%d\n", sum);
}
... I'm getting a huge number when it should be zero.
int main(void)
{
int i[4], j, k;
k = 0;
for (j = 0; k < 4; ++j)
k = k + i[j];
printf("%d\n", k);
}
I know in this case a simple alternative would beint i[4]={0,0,0,0};
*i type of non-character, i'm not sure if this is portable/right:
memset(i, 0, sizeof i);
You know that's c99. I use c89. You know if I tried what you intended my
compiler would hang.
Barry Schwarz said:... I'm getting a huge number when it should be zero.
int main(void)
{
int i[4], j, k;
k = 0;
for (j = 0; k < 4; ++j)
k = k + i[j];
printf("%d\n", k);
}
I know in this case a simple alternative would be
int i[4]={0,0,0,0};
*i type of non-character, i'm not sure if this is portable/right:
memset(i, 0, sizeof i);
This will set every byte of the array i to all bits zero. On most
systems, this will cause each int in the array to have the value 0.
Barry Schwarz said:... I'm getting a huge number when it should be zero.
int main(void)
{
int i[4], j, k;
k = 0;
for (j = 0; k < 4; ++j)
k = k + i[j];
printf("%d\n", k);
}
I know in this case a simple alternative would be
int i[4]={0,0,0,0};
*i type of non-character, i'm not sure if this is portable/right:
memset(i, 0, sizeof i);
This will set every byte of the array i to all bits zero. On most
systems, this will cause each int in the array to have the value 0.
Bill Cunningham said:You know that's c99. I use c89. You know if I tried what you intended my
compiler would hang.
Bill Cunningham said:You know that's c99. I use c89. You know if I tried what you intended my
compiler would hang.
int main(void)
{
int i[4], j, k;
Nope. The values of *variables* which aren't initialized aren't zero
by default. If something is even partially initialized, though, it is
treated as though it were fully initialized with anything not initialized
explicitly being initialized to zero.
the array `i' isn't static durable, i think only the first element are
initialized in the following, and the rest of them, i[1], i[2], i[3]
are indeterminate.
int main(void)
{
int i[4] = {0};
/* ... */
Please correct me if I am wrong. Thanks.
[email protected] said:i meant the elements in the array `i' mentioned in this thread:
int main(void)
{
int i[4], j, k;Nope. The values of *variables* which aren't initialized aren't zero
by default. If something is even partially initialized, though, it is
treated as though it were fully initialized with anything not initialized
explicitly being initialized to zero.
the array `i' isn't static durable, i think only the first element are
initialized in the following, and the rest of them, i[1], i[2], i[3]
are indeterminate.
int main(void)
{
int i[4] = {0};
/* ... */
Please correct me if I am wrong. Thanks.
^^^^^^the array `i' isn't static durable, i think only the first element are
initialized in the following, and the rest of them, i[1], i[2], i[3]
are indeterminate.int main(void)
{
int i[4] = {0};
/* ... */Please correct me if I am wrong. Thanks.
As I said in the previous post: Yes, you are wrong.
6.7.8, paragraph 21:
initialized implicitly the same as objects that have static storage
^^^^^^Or paragraph 19:
the same as objects that have static storage duration.
[email protected] said:^^^^^^the array `i' isn't static durable, i think only the first element are
initialized in the following, and the rest of them, i[1], i[2], i[3]
are indeterminate.int main(void)
{
int i[4] = {0};
/* ... */Please correct me if I am wrong. Thanks.
As I said in the previous post: Yes, you are wrong.
6.7.8, paragraph 21:
initialized implicitly the same as objects that have static storage ^^^^^^
Or paragraph 19:
the same as objects that have static storage duration.
They all mentioned `static'.
I can understand that three rest of `a'
and `b' are zero. Array `i' is an auto variable, three rest of `i' are
indeterminate.
int a[4] = {100};
int main(void)
{
int i[4] = {0};
static int b[4] = {1000};
/* ... */
[email protected] said:...They all mentioned `static'.
[email protected] said:^^^^^^the array `i' isn't static durable, i think only the first element are
initialized in the following, and the rest of them, i[1], i[2], i[3]
are indeterminate.
int main(void)
{
int i[4] = {0};
/* ... */
Please correct me if I am wrong. Thanks.
As I said in the previous post: Yes, you are wrong.
6.7.8, paragraph 21:
initialized implicitly the same as objects that have static storage ^^^^^^
Or paragraph 19:
the same as objects that have static storage duration.
They all mentioned `static'.
Yes, because the standard writer does no want to repeat the complex
wording used to describe the zero initialisation of statics, so the
effect of a partial initialisation is described by referring to the
method used for statics. p19 does, none the less, apply to aggregates
with automatic storage duration.
There are 22 paragraphs in that section (and 17 clarifying examples)
so you probably have to read the whole thing to see the big picture.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.