[英]what is char i=0x80 and why overflow did not happen in bit shifting
[英]Why did this happen when I compiled C?
我嘗試編譯,我希望它沒有錯誤(成功)。 有關詳細信息,請參閱https://discord.com/channels/1015095797689360444/1019720925035364422/threads/1056376466612432936基本上,我創建了這個文件:
#include <stdio.h>
int main(){
int num = 100; double pi = 3.1415926536;
printf("Integer is %d \n",num);
printf("Values are %d and %f \n",num,pi);
printf("%%7d displays %7d \n",num);
printf("%%07d displays %07d \n",num);
printf("Pi is approximately %1.10f \n",pi);
printf("Right-aligned %20.3f rounded pi \n",pi);
printf("Left-aligned %-20.3f rounded pi \n",pi);
return 0;
}
作為/Users/farhanaazmohammed/Code/vars/c
,當我編譯為vars/exe
時,我得到:
ld: warning: ignoring file c, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x23 0x69 0x6E 0x63 0x6C 0x75 0x64 0x65 0x20 0x3C 0x73 0x74 0x64 0x69 0x6F 0x2E )
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
為什么只在匯編中編譯出錯,這是什么意思?
用 C 編寫的程序應該在名稱擴展名為.c
的文件中。 例如,您可以將文件命名為display.c
甚至c.c
。
但c
不是有效名稱。 編譯器假定它已經編譯並嘗試將它直接傳遞給 linker,但這是行不通的。 由於 linker 拒絕文件,編譯器放棄。
您可以使用-x
選項來定義文件的類型,但最好選擇一個合適的名稱。
也許你正在使用 clang,這是外部編譯器
嘗試使用此代碼:
g++ <file.cpp>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.