I'm currently coding some encryption algorithm, and I am facing a GCC compilation error I can't understand. Here is the problem :
In my int main(void)
function I got :
uint32_t block[2];
memset(block, 0x0, sizeof(block));
printf("%ld \n", sizeof(block));
Which looks okay for GCC.
Then, I pass this uint32_t array named block
to a function :
void readOneBlockFromFile(int fd, uint32_t block[2]){
if(fd == -1){
perror("fd");
errno = EIO;
exit(errno);
}
int nb_bytes_read = 0;
while(1){
memset(block, 0x0, sizeof(block));
nb_bytes_read = read(fd, block, sizeof(block));
if(nb_bytes_read == -1){
perror("read");
exit(errno);
}
if(nb_bytes_read == 0){
break; //EOF
}
}
}
And here I get some GCC warnings :
SPN.c: In function ‘readOneBlockFromFile’:
SPN.c:46:30: warning: ‘sizeof’ on array function parameter ‘block’ will return size of ‘uint32_t * {aka unsigned int *}’ [-Wsizeof-array-argument]
memset(block, 0x0, sizeof(block));
^
SPN.c:38:44: note: declared here
void readOneBlockFromFile(int fd, uint32_t block[2]){
^~~~~
SPN.c:47:43: warning: ‘sizeof’ on array function parameter ‘block’ will return size of ‘uint32_t * {aka unsigned int *}’ [-Wsizeof-array-argument]
nb_bytes_read = read(fd, block, sizeof(block));
^
SPN.c:38:44: note: declared here
void readOneBlockFromFile(int fd, uint32_t block[2]){
^~~~~
So my GCC is giving me warning when I'm using block
without using block[0]
or *block
.
I can't figure out why GCC gives me warning for this, as I can do the same stuff without any problem in main.