Pixel Pedals of Tomakomai

北海道苫小牧市出身の初老の日常

C言語の多次元配列の型はどう読むのか

int a[2][3] って、「整数2個の配列( int a[2] )を 3個の配列( [3] )にした、と読めるけどどうなのか1http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf と比べて確認。

116ページのArray declaratorsの節によると、 T D[n] という形式のときは「… array of T」となると書かれている。ここで T は int で D は a[2]n3 なので、「整数3個の配列… 」となる。 … の部分は仕様上で “derived-declarator-type-list” と呼ばれている部分で、 T D がどういう型かによって定められる。 int a[2] は「2-array of int」だけど、 … は最後の int は除くことになっているので、まとめると「2-array of 3-array of int」であって、「整数3個の配列の2個の配列」という意味になる。

なんとも歯切れの悪い定義だけど、 int の何かを定義しているってことでこうなっているのだろうか。考え方としては、 「int D[3]」 みたいな定義があるともうこれは整数3個からなる配列であり、Dをどう書くかでそいつをどう調理するかが決まるってだけ。 a[2] と書けばそれを 2 個の配列にするし、 *a って書けばそいつへのポインタになる。


  1. 添字でのアクセスを考えると違うだろってのはすぐ想像つくけど。

man introとcalコマンド

月末って何曜日だっけとかってときいつもgoogleカレンダー開いてたんだけど、これでいいじゃん。知らなかった・・・。

ubuntu:~$ cal
      May 2017
Su Mo Tu We Th Fr Sa
    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 26 27
28 29 30 31

man 1 intro したら書いてあった。 man intro なんて初めて使ったし、そもそも man の基本的な使い方もわかってないよね。適切な情報を得る術を知らずに何年も費やしても、まともな知識は得られないってことだね。

VMWareのインストール

最近ずっとVirtualBoxを使っていたのだけど、3Dアクセラレーションを有効にするとOpenGLがまともに動かなかったので、代わりとして久々にVMWareを入れてみた。

Ubuntu 17.04 を入れたんだけど、 Install VMWare tools が動かなかったので、 /media/ユーザ名/VMWare\ Tools 以下のファイルを /tmp へ展開し、手で ./vmware-install.pl を叩いて入れた。途中 ifconfig がなくて怒られたので、 sudo apt-get update sudo apt install net-tools した上で /sbin/ifconfig を手で指定したら動いたっぽい。

目的だったOpenGLは、すんなりと動いてくれた。後、VirtualBoxディスプレイが大き過ぎるとゲストOSのディスプレイサイズがバグる というしょーもない問題も起きなくなった。このまま乗り換えたほうがいいんじゃないかってくらい快適。

もう少し弄って満足したらそのまま乗り換える。

monadiusを動かす

12年前に書かれた http://www.geocities.jp/takascience/haskell/monadius_ja.html を手元で動かした。と言っても、ほぼ手を加えずにそのまま動いた。

$ diff -ur monadius.BK/ monadius
diff -ur monadius.BK/src/Main.hs monadius/src/Main.hs
--- monadius.BK/src/Main.hs     2017-05-16 08:02:04.566956400 +0900
+++ monadius/src/Main.hs        2017-05-16 08:08:18.524217900 +0900
@@ -49,7 +49,8 @@
 loadReplay::String-> IO ReplayInfo
 loadReplay filename = readFile filename >>= (return.read)

-main = withMusic $ do
+main = withMusic $ do
+  getArgsAndInitialize
   args <-getArgs
   putDebugStrLn $ show args

@@ -109,7 +110,7 @@
   mainLoop
   destroyWindow curwnd

-  `catch` (\exc -> return ())
+  `catch` (\exc -> print (exc :: SomeException))

   where
   getReplayFilename args = if length candidates == 0 then Nothing else Just (head candidates) where
@@ -119,7 +120,7 @@
   removesuffix str = if '.' `elem` str then (removesuffix.init) str else str

 exitLoop = do
-  throwIO $ ExitException ExitSuccess
+  exitWith ExitSuccess

 initMatrix = do
   viewport $= (Position 0 0,Size 640 480)
@@ -375,9 +376,9 @@

 closeProc = do
   putDebugStrLn "closed"
-  throwIO $ ExitException ExitSuccess
+  exitWith ExitSuccess


 savePoints = [0,1280,3000,6080]

-
\ No newline at end of file
+

diff -ur monadius.BK/src/Monadius.hs monadius/src/Monadius.hs
--- monadius.BK/src/Monadius.hs 2017-05-16 08:02:04.582583000 +0900
+++ monadius/src/Monadius.hs    2017-05-16 08:02:24.097737300 +0900
@@ -5,7 +5,7 @@
   shotButton,missileButton,powerUpButton,upButton,downButton,leftButton,rightButton,selfDestructButton
 )where

-import Graphics.UI.GLUT hiding (position)
+import Graphics.UI.GLUT hiding (position, DebugMessage)
 import Graphics.Rendering.OpenGL.GLU
 import Control.Exception
 import Control.Monad

freeglut導入済みのmingw64でビルド。Windows上でビルドしたので音も出る。Cのコードも入っているので注意。

$ cd src
$ stack exec makefile.bat

と、これで動いたのだけど、5年前に自分で作ったパッチ を見ると、 (_, args) <- getArgsAndInitialize とするのが正しいらしい。まあいいや。

ちなみに、 Surface Book 上で動かしているのだけど、微妙に動きに引っかかりを感じる。引っかかる程度でほぼなめらかには動いているのだけど。

2017/5/18追記: hackageにも上がってた

shu-thing (シューティングもどき) を動かす

12年前にhaskellで書かれた shu-thing を手元で動かした。と言っても、ほとんど何もせずに動いてしまった。

@@ -10,6 +10,7 @@
 import System.Process

 main = do
+  getArgsAndInitialize
   keystate <- newIORef []
   cp       <- newIORef (openingProc keystate)
   initialWindowSize $= Size 640 480
@@ -44,9 +45,9 @@
   mainLoop
   destroyWindow wnd

-  `catch` (\exc -> return ())
+  `catch` (\exc -> print (exc :: SomeException))

-exitLoop = throwIO $ ExitException ExitSuccess
+exitLoop = exitWith ExitSuccess

 initMatrix = do
   viewport $= (Position 0 0,Size 640 480)
@@ -184,7 +185,7 @@

 closeProc = do
   putStrLn "closed"
-  throwIO $ ExitException ExitSuccess
+  exitWith ExitSuccess

 bosstime=6600
 bosstime2=7200
$ stack ghc -- -o shu-thing.exe gl.hs
[1 of 1] Compiling Main             ( gl.hs, gl.o )
Linking shu-thing.exe ...

freeglut 入りの mingw64 でビルド、実行している。

2017/5/18追記: hackageにも上がってた

Mac Pro と BRAVIA の HDMI 接続

Mac Pro(ゴミ箱) と sonyBRAVIAHDMI で繋いでいるのだけど、まったく安定しない。具体的に言うと、認識しないことがほとんど。BRAVIAMac Proの電源をON OFFしつつHDMIケーブルをポートを変えつつ何度も何度も何度も何度も何度も何度も差し替えると、運良く映る日もある。映らない日がほとんど。

なので、悲しいことに VNC で接続している。

今日は、PS4 Proが使っているHDMIケーブルに差し替えてみたら繋がった。けど、Mac Proが使っているケーブルでPS4 Proは接続できているので、ケーブルは悪くない。まったく切り分けができない。