This compiles without warning in VC9 at warning level 4. Why DO NOT consider this a compiler defect?

I saw some published code with an error outside the SO range, which made me think. I expect the compiler to generate a warning (at the highest level at least) for this code

#pragma warning(push,4)
int main(){
    int x[2];
    x[2]=0;     
    return 0;
}
#pragma warning(pop)

but this is not so.

The EDG compiler perfectly says:

"sourceFile.cpp", line 3: warning:
          subscript out of range
          x[2]=0;
          ^

Actually the EDG says a bit more (all of which are expected)

"sourceFile.cpp", line 1: warning: 
          unrecognized #pragma
  #pragma warning(push,4)
          ^

"sourceFile.cpp", line 4: warning: 
          subscript out of range
      x[2]=0;     
      ^

"sourceFile.cpp", line 3: warning: 
          variable "x" was set but never used
      int x[2];
          ^

"sourceFile.cpp", line 7: warning: 
          unrecognized #pragma
  #pragma warning(pop)

but that is not my question.

I am considering this failure to prevent SERIOUS skipping errors in VC9 (especially since with an automatic variable !!!!). Can someone give me a good reason to change my mind?

+4
source share
7 answers

.

C, . .

  • , x[i] i[x] - C. "string"[2] 2["string"] . . , x[i] *(x + i), C , , , , .

  • , , .

    struct s {
        ...bunch of stuff...
        int points[1]; // not really [1]
    };
    ...
    struct s *p = malloc(sizeof (struct s) + someNumber * sizeof(int));
    

    , ...     : heh, fooobar.com/questions/1032947/....

+17

undefined ( "", ). , . , VSTS, , , . , , (, ), , .

+8

, ( AST).

, .

, ++. , , , .

FWIW: g++ -Wall .

+7

, . , ( , ) .

C/++. , .

+5

, , , . :

int main(){
    int x[2];
    x[2]=0;     
    return 0;
}

, , , :

  • - , ,
  • .

. , . , , , . , , , .

, , , , , , .

:

void foo(int* x){
    x[2]=0;     
}

:

void foo(int i){
    int x[2];
    x[i]=0;
}

. . , ++ , , . , , . , , ?

, , , :

VC9 ( **!!!! **). - ?

. . , , , , , , .

+3

.

0

, :

  • , . - :

    #pragma warning(push,4)
    int main(){
        return 0;
    }
    #pragma warning(pop)
    
  • , ( - ---). , . , , . ? , , , , , . , ? , ? , , ..... ( ).

I am not saying that this warning is not useful - it is just not as clear as you think it is.

0
source

All Articles