A lot of my programming revolves around acquiring and processing images. Whilst I love /CHECKMATE, the FULL_UNDEF feature does mean that extra care needs to be taken when manipulating images pixel-by-pixel. FULL_UNDEF causes a run-time error on any attempt to make reference to a single byte of memory with value 0x80. This is vexing, because once you get down to single-byte image data, 0x80 is a perfectly reasonable value that is liable to be sprinkled liberally throughout most images with mid-range pixel values. I have posted about this before.
A little while ago, I thought I had come up with a general-purpose solution. Isolate the code that accesses the single-byte data in a module, and compile it with /DEBUG, then link that module with all the other code compiled with /CHECKMATE.
The following code illustrates that this is not the end of the story. The program shows four different examples of trying to put 0x80 somewhere, and four different examples of trying to get it back again, using a module compiled with /DEBUG.
The first half of the code shows that putting 0x80 into memory can be achieved with the module approach. Example 3 shows a curious anomaly that, bearing example 2 in mind, I definitely do not understand. It does prove, however, that it *is *possible, in CHECKMATE-compiled code, to put 0x80 into a memory location associated with a single-character variable without resorting to the module approach.
The second half of the code, on the other hand, shows that getting 0x80 out of memory and into a 'naked' single-character variable is not so easy, even *with *the module approach. I definitely do not understand why example 6 does not work, since the reference to 0x80 takes place within the DEBUG-compiled module. On the other hand, examples 7 and 8 show that it is no problem at all to get 0x80 out of memory in an 'intermediate' capacity (albeit example 8 shows that even FTN95 is getting a little confused).
The saving grace, of course, is that I am never interested in single-character values other than as code for integers in the range 0-255, so I have never yet found a need for them as naked single characters, only as intermediates that can be nested away ... on the other hand, I am not a fan of nesting expressions, so I'd like to be able to define single-character variables, certainly during development (not least because, from time to time, I have known FTN95 to choke on nesting that should be no problem, particularly LOGICAL-based nesting).
Can anyone explain why example 3 coerces FTN95 into doing something apparently impossible? Or why example 6 fails to get it to do something apparently possible?
Paul, can you add the false warning provoked by example 8 to your list of things to attend to at some point, please?
Andy
program uncharacteristic
use core_manipulation
character chai, chao
integer i, ptr, ichao
ptr = loc (chai)
!PUTting 0x80 somewhere is not too difficult
!1 naked 0x80 causes FULL_UNDEF error, reasonably enough !1 chai = char (128) !
!2 ... and the same here !2 ccore1 (ptr) = char (128)
!3 curiously, this near-naked 0x80 does NOT cause a problem!? !3 do i = 128,128 !3 chai = char (i) !3 end do
!4 this line PUTs a naked 0x80 where it is wanted by stealth !4 (PROVIDED putchar is compiled only with DEBUG and not CHECKMATE) call putchar (ptr, char (128))
!GETting a naked 0x80 from somewhere appears to be impossible
!5 causes FULL_UNDEF error !5 chao = ccore1 (ptr)
!6 causes FULL_UNDEF error !6 (even when getchar is compiled with DEBUG rather than CHECKMATE)!? !6 chao = getchar (ptr)
!7 does not cause FULL_UNDEF error !7 ichao = ichar (getchar (ptr))
!8 even this does not cause FULL_UNDEF error!? !8 (but it does cause an erroneous warning #362) ! ichao = ichar (ccore1 (ptr))
stop
end program uncharacteristic
module core_manipulation
contains
!------------------------------------------------ character function getchar (ptr) integer ptr getchar = ccore1 (ptr) end function getchar !------------------------------------------------ subroutine putchar (ptr, chi) integer ptr character chi ccore1 (ptr) = chi end subroutine putchar !------------------------------------------------ end module core_manipulation