C 言語にはダイグラフとよばれる環境により存在しない記号の代替となる記法を提供している。2 文字のトークンで 6 種類ある。
- <: => [
- :> => ]
- <% => {
- %> => }
- %: => #
- %:%: => ##
例えば、以下のような簡単なソースコードがあったとする。
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
int hoge[] = { 123 };
printf("%d
", hoge[0]);
exit(0);
}
これは普通に動作するコードです。
$ mkdir -p bin
gcc ./src/main.c -o ./bin/main -Wall
$ ./bin/main.c
123
このソースコードをダイグラフを使ったものに差し替えてみる。
%:include <stdio.h>
%:include <stdlib.h>
int main(int argc, char *argv<::>) <%
int hoge<::> = <% 123 %>;
printf("%d
", hoge<:0:>);
exit(0);
%>
すると、ふつうにコンパイルできます。
$ mkdir -p bin
gcc ./src/main.c -o ./bin/main -Wall
$ ./bin/main.c
123
トライグラフなるものもあるようだが、gcc ではデフォルトでオフってあるそうです
ところでダイグラフってどういう意味?
ダイグラフ (英語: digraph)
二重音字
合字
Pascal などのコンピュータ言語で記号 1 文字を 2 文字で書き表すこと。例:「(.」→「[」。背景・目的などはトライグラフを参照。
Wikipedia より
Pinned Articles
About
ウェブ界隈でエンジニアとして労働活動に励んでいる @gomi_ningen 個人のブログです
Tags
LLM
promptfoo
GenAI
JavaScript
PowerShell
elasticsearch
fluentd
kibana
nginx
五十嵐裕美
村川梨衣
イベント
logrotate
IoT
Scala
Java
ICMP
iputils
C言語
WUG
mastodon
Swift
AWS
Windows
Clock
PoEAA
アーキテクチャ
DeviceFarm
iOS
プログラミング言語
OS
Lambda
StepFunctions
Serverless
terraform
ポエム
ネットワーク
RHEL
GraphQL
CloudWatch
Coreutils
Linux
telnet
nc
network
LinuxKernel
fpinscala
ELB
IAM
AppSync