討論串[閒聊] 不使用if的寫法
共 18 篇文章

推噓1(1推 0噓 0→)留言1則,0人參與, 最新作者pziyout (pziyout)時間12年前 (2013/01/10 11:48), 編輯資訊
0
0
0
內容預覽:
( i == 1 || cout << "no\n" && 0 ) && cout << "yes\n" ;. 利用 short-circuit operator 的特性. A || B --> if ( !A ) B. A && B --> if ( A ) B. --. 發信站: 批踢踢實業

推噓3(3推 0噓 6→)留言9則,0人參與, 最新作者azureblaze (AzureBlaze)時間12年前 (2013/01/09 01:32), 編輯資訊
0
0
0
內容預覽:
unsigned int u = 0x6f6e + (~-!!(i-1)&0x72F60B);. printf("%s\n",(char*)&u);. 限定little endian,big endian改一下就行就是了.... 沒有branch,沒有pointer indirection. 只是我

推噓3(3推 0噓 1→)留言4則,0人參與, 最新作者zhouer ( )時間12年前 (2013/01/08 23:55), 編輯資訊
0
0
0
內容預覽:
void handler(int a). {. printf("yes\n");. exit(0);. }. int main (int argc, char *argv[]). {. signal(SIGFPE, handler);. int i = 1;. int a = 1 / (i - 1)

推噓0(0推 0噓 0→)留言0則,0人參與, 最新作者del680202 (HANA)時間12年前 (2013/01/08 20:23), 編輯資訊
0
0
0
內容預覽:
湊個熱鬧. 前面提的陣列法. 如果只有兩種答案,i為0~65535,不用任何判斷式. char* str[] = {"no","yes"};. int i = n & 65535;. printf("%s",*(str+(i&1)));. 這樣就算換成組語也不會有jmp等指令出現. --. 發信

推噓1(1推 0噓 0→)留言1則,0人參與, 最新作者johnlinvc (阿翔)時間12年前 (2013/01/08 16:54), 編輯資訊
0
0
0
內容預覽:
Patern matching. Haskell. Code:. let yn 1 = "yes". yn _ = "no". Output:. yn 0 => "no". yn 1 => "yes". --. 發信站: 批踢踢實業坊(ptt.cc). ◆ From: 220.128.223.1