成果を出しながら成長する、アウトプット駆動のキャッチアップ術 / Output-driven catch-up techniques to grow while producing results

#include <stdio.h> void fizzbuzz(int n) { int next; int i = 1; do { printf(i % 15 ? i % 5 ? i % 3 ? "%d\n" : "Fizz\n" : "Buzz\n" : "FizzBuzz\n", i); if (i++ >= n) next = 0; } while (next); } int main(void) { printf((char[]){""}); // この位置にprintfが無いとなぜか動かない fizzbuzz(100); } gcc 10.1.0 を使用し、コンパイラが感知したミスには警告を出力してくれる様 -Wall -Wextra を指定し、最適化指示なしでコンパイル、動作させたところ動作するが Wandboxで実行 main() の中の何も出力していない printf(
def check(n) s = "*"*n f = open("test.cpp","w") f.puts <<EOS #include <cstdio> int main(){ (#{s}printf)("Hello World\\n"); } EOS f.close() return system("clang++ test.cpp") end check(ARGV[0].to_i) $ ruby check.rb 10000 clang: error: unable to execute command: Illegal instruction: 4 clang: error: clang frontend command failed due to signal (use -v to see invocation) Apple LLVM version 10.0.1 (clang
この記事話題になってますね。セキュリティホールの宝石箱や!って感じ。 https://qiita.com/hamichamp/items/7b7a7ee091a6856ac900 同じ作者の記事で、問題あるのがまだまだ掘れそうだなぁと思ったので、キャストの記事について突っ込んでみます。 https://www.sejuku.net/blog/25737 数値型の精度 まず数値の精度について、以下の順と紹介されてるけど、明らかに間違いですね。 精度の順序は下記のとおりです。 double型 > float型 > long (int)型 > int型 > short (int)型 > char型 longとfloatのどちらが精度が良いか?longで表せる整数範囲に限っては十中八九longの方が良いです。 (処理系依存の話ですが一般的なx86PCであれば)long型とfloat型はともに32b
# include <stdio.h> # include <stdlib.h> // 構造体の宣言 typedef struct { int num; char *str; } strct; int main(void) { // 実体を生成 strct *entity; // 動的メモリの確保。確保したメモリをstrct型ポインタにキャスト。 entity = (strct*)malloc(sizeof(strct)); // メンバの初期化 entity->num = 0; entity->str = (char*)malloc(sizeof(32)); // メモリに文字列を代入 sprintf(entity->str, "%s %s!", "Hello", "World"); printf("%s\n", entity->str); // メモリの解放 free(entity->
2013/04/30 タイトル修正 昨日、とある場所でこんな話で盛り上がった。 逆ポーランド計算機を作ろうと思ったんだけど、どうも結果が期待通りにならない。 ソースコードを見せて貰うと以下の様なコードだった。 #include<stdio.h> #include<stdlib.h> #define MAX_SIZE 100 int stack[MAX_SIZE]; int stack_pointer = 0; void push(int data){ stack[stack_pointer++] = data; } int pop(){ return stack[--stack_pointer]; } int pop1(int n){ printf("pop %d\n", n); return stack[--stack_pointer]; } int main(void){ char s
最近、Robert Love先生の本を暇な時にダラーと読んでいたりするわけですが、それの中にLinux Kernel内部で使われているLinked Listの実装が書いてあって面白かったので共有。 まず、Linked Listの一個一個のエントリを表すstructを定義します。 struct list_head { struct list_head *next, *prev; }; いやいやいやいや。いかにC力の低い僕でも流石にこれはあきません。騙されませんよ。前後のエントリへのポインタは確かにあるけれども、これにはデータを指すためのポインタがないじゃないの。おじいちゃんまたデータ忘れてきちゃったの?いやあねえ。 おじいちゃんは言った。「それはお前の短見というものじゃ。このLinked Listは以下のコードのようにデータ構造に埋め込んで使うものなんじゃよ。」そしてそれは正しかった。 st
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く