monarch_dodra:

So basically, this is saying "If your C code compiles in D, you'll get the same result. I guarantee it :)"

It's a general rule, but it has some exceptions, like C programs that rely on global floating point variables initialized to 0, or when you use a fixed-sized array, that D passes by value and C by pointer.


Here's a (reduced) C program:

----
int i = 3;

void main()
{
  {
    int some_condition = 1;
    if ( some_condition )
      goto block_end;

    /* dummy code */
  } block_end:

  {
    int i = 7;
    printf("%i", i);
  }

  printf("%i", i);
}
----
C prints: "70"
D prints: "77"

This should go in some page that lists the differences between C and D.


if anybody can think of a rationale for the current behavior. And if there is no rationale, how much support there is for changing it.

It's bad to break C backwards compatibility for free, so if it's not useful for D then and it should be fixed.

Bye,
bearophile

Reply via email to