NO

Author Topic: Weird warning. Version 2.90.2 beta 8  (Read 3101 times)

xanatose

  • Guest
Weird warning. Version 2.90.2 beta 8
« on: October 26, 2004, 08:54:07 pm »
If you compile this code with warning 2

Code: [Select]

#include <stdio.h>
#include <string.h>

int main(void) {
  static const char errLog[] = "err.txt";
  char name[256];
  printf("Length = %d\n", sizeof(errLog));
  memcpy(name,errLog,sizeof(errLog));
  printf("String = %s\n", name);
  return 0;
}


You get the following warning in the memcpy line:
Code: [Select]

warning #2046: Expression with no effect removed.


However, the line is not removed. So basically its just a weird warning.

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2076
    • http://www.smorgasbordet.com
Weird warning. Version 2.90.2 beta 8
« Reply #1 on: October 26, 2004, 10:03:43 pm »
This happens if you use the intrinsic form of memcpy() - usually when optimizing for speed. If you don't use the return value from memcpy(), which is pretty normal, you will get this warning.

The problem is that the expression for the inline form of memcpy() is built in one part of the compiler, which has no way of informing another part of the compiler, where the warning is issued. The warning can be helpful, so I don't want to remove it.

The warning is annoying, and known, but until I find a reasonable simple solution to fix it, I rather leave it for now.

Pelle
/Pelle