Product : ISaGRAF NT Target 3.x

Date    : 24-Febuary-1997

File    : EasyIO.EasyIO access memory inputs via driver kmemnt.sys.htm

Subject : EasyIO access memory inputs via driver kmemnt.sys

Keywords: EasyIO - kmemnt - I/O - NT target



Scanning in a loop one boolean input via a pointer in the

memory mapped in my process, when the input changes, the value

read by the pointer doesn't change. Following is an example of the


char *booPtr = memory_address ;

while( *booPtr && !time_out )

time_out-- ;


The problem comes from your compiler, which optimizes this kind

of loop by extracting what is called the loop constants. The

resulting loop will look like following:

char *booPtr = memory_address ;

while( !time_out )

time_out-- ;

Because, you don't do anything with the *booPtr variable, the

optimizer, keeps it away from the loop. In the ANSI C, there is a

keyword to tell the optimizer that the variable can be changed by

another process (or hardware, or operating system). The keyword is

'volatile'. The declaration of the pointer should be of the

following form:

volatile char *booPtr ; /* This means that the value pointed

to by the pointer is volatile */

In this case, the loop will be optimized, so that the value

*booPtr will be read at each loop.


Copyright © 1996-2009 ICS Triplex ISaGRAF Inc. All rights reserved.