Sujet : Re: C23 thoughts and opinions
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.cDate : 31. May 2024, 16:34:29
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240531081143.419@kylheku.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2024-05-31, bart <
bc@freeuk.com> wrote:
Here's how builtin embedding worked using a feature of my older C compiler:
>
#include <stdio.h>
#include <string.h>
>
char hello[] = strinclude("hello.c");
>
int main(void) {
printf("hello =\n%s\n", hello);
printf("strlen(hello) = %zu\n", strlen(hello));
printf("sizeof(hello) = %zu\n", sizeof(hello));
}
Lisp:
$ cat strincl.tl
(defmacro strinclude (path)
(put-line `including @path`)
(file-get-string path))
(defun test()
(strinclude "/etc/hostname"))
When we run it interpreted we see from the debug put-line that /etc/hostname is
included at macro-expansion time before we run the test function:
$ txr -i strincl.tl
including /etc/hostname
This TTY may be recorded for privacy-violating and evidence-gathering purposes.
1> (test)
"sun-go\n"
Now compile the file: the file is pulled it at compile time. Twice. :)
A double expansion took place due to certain complexities of compiling.
$ txr --compile=strincl.tl
including /etc/hostname
including /etc/hostname
Now when we load the compiled file, the diagnostic trace
"including /etc/hostname" no longer appears: the string is part of the test
function as a literal:
$ txr -i strincl
TXR is enteric coated to release over 24 hours of lasting relief.
1> (test)
"sun-go\n"
-- TXR Programming Language: http://nongnu.org/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca