6.1.0860 C, c-comma CORE
Reserve space for one character in the data space and store char in the space. If the data-space pointer is character aligned when C, begins execution, it will remain character aligned when C, finishes execution. An ambiguous condition exists if the data-space pointer is not character-aligned prior to execution of C,.
See:
Testing:
HERE 2 C,
CONSTANT 2NDC
CONSTANT 1STC
T{ 1STC 2NDC U< -> <TRUE> }T \ HERE MUST GROW WITH ALLOT
T{ 1STC CHAR+ -> 2NDC }T \ ... BY ONE CHAR
T{ 1STC 1 CHARS + -> 2NDC }T
T{ 1STC C@ 2NDC C@ -> 1 2 }T
T{ 3 1STC C! -> }T
T{ 1STC C@ 2NDC C@ -> 3 2 }T
T{ 4 2NDC C! -> }T
T{ 1STC C@ 2NDC C@ -> 3 4 }T
ContributeContributions
NieDzejkob [49] Suggested reference implementationSuggested reference implementation2018-01-08 17:54:46
: C, ( char -- ) HERE @ TUCK ! CHAR+ HERE ! ;
ruv [194] Additional test for UTF-16Suggested Testcase2021-04-28 22:47:11
Somebody could think that UTF-16 is a valid string representation in memory, having the char size = 1 byte (see a discussion/raw message in comp.lang.forth).
This test case ensures that C,
stores a primitive character (a code unit).
T{ ALIGN HERE CHAR A C, CHAR B C, CHAR C C, 3 S" ABC" COMPARE -> 0 }