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
GenAI
JavaScript
PowerShell
fluentd
kibana
elasticsearch
nginx
五十嵐裕美
村川梨衣
イベント
logrotate
IoT
Java
Scala
ICMP
iputils
C言語
WUG
mastodon
AWS
Swift
Clock
Windows
PoEAA
アーキテクチャ
iOS
DeviceFarm
プログラミング言語
OS
StepFunctions
Lambda
Serverless
terraform
ポエム
RHEL
ネットワーク
GraphQL
CloudWatch
Linux
Coreutils
nc
telnet
network
LinuxKernel
fpinscala
ELB
IAM
AppSync
EFS
Gradle