Compiler Warning (level 3) C4197
Collapse the table of content
Expand the table of content
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

Compiler Warning (level 3) C4197

'type' : top-level volatile in cast is ignored

The compiler detected a cast to an r-value type which is qualified with volatile, or a cast of an r-value type to some type that is qualified with volatile. According to the C standard (6.5.3), properties associated with qualified types are meaningful only for l-value expressions.

The following sample generates C4197:

// C4197.cpp
// compile with: /W3
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>

void sigproc(int);
struct S
   int i;
} s;

int main()
   signal(SIGINT, sigproc);
   s.i = 1;
   S *pS = &s;
   for ( ; (volatile int)pS->i ; )   // C4197
   // for ( ; *(volatile int *)&pS->i ; )   // OK
   //    break;

void sigproc(int) // ctrl-C
   signal(SIGINT, sigproc);
   s.i = 0;

© 2015 Microsoft