Using sizeof operator on variable-length arrays gives an incorrect Expression with no effect removed. warning.
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
int main( void )
{
const size_t size = 12 ;
char a[size] ; //warnings are not present if size is constant: char a[12] ;
size_t a_size = sizeof( a ) ;
int n = snprintf( a , a_size , "Copy text ABCDEFG." ) ;
printf("%s\n%d\n" , a , n ) ;
n = snprintf( a , sizeof( a ) , "Copy text ABCDEFG." ) ;
printf("%s\n%d\n" , a , n ) ;
printf( "%zu" , sizeof( a ) ) ;
return 0 ;
}
Gives warnings:
main.c(11): warning #2046: Expression with no effect removed.
main.c(17): warning #2046: Expression with no effect removed.
main.c(20): warning #2046: Expression with no effect removed.
Level 2 warnings must be used. Optimization or other project options don't have any effect. I get this result on 32bit RC5 and RC4 version.