C/C++ Newbie's FAQ
Part I ÈçºÎÉÏ·
1. vi, vimÊDZàÒëÆ÷ô£¿
vi means visual editor£¬ÊÇÈí¼þÊÀ½çµÚÒ»¸öÈ«ÆÁÄ»±à¼Æ÷£¬×î³õµÄ×÷ÕßÊÇÏÖÔÚSun microsystemµÄBill Joy¡£
vim means Vi IMproved£¬¿ÉÒÔ¿´×÷ÊÇÔöÇ¿µÄvi¡£
ºÜ²»ÐÒ£¬ËûÃǶ¼²»ÊDZàÒëÆ÷£¬Èç¹ûÄãÒѾдºÃÁËfirst.c£¬ÄÇô²»ÄÜÖ¸ÍûviÃǽ«ÄãµÄÔ´´úÂë±ä³ÉÖ´ÐгÌÐò¡£
2. gcc, g++ÕâЩ¶¼ÊǸÉʲôÓõÄ
gcc means GNU C Collector£¬ÊÇGNUµÄÆì½¢Èí¼þ£¬×ÔÓÉÈí¼þ£¬CÓïÑÔ±àÒëÆ÷¡£
g++ ÊÇGNUµÄC++±àÒëÆ÷¡£
3. ÄÇôcc, CC, ld, makeÕâЩ³ÌÐòÓÖÊǸÉʲôµÄÄØ£¿
ccÊÇunix worldÖжÔc±àÒëÆ÷µÄ½Ð·¨£¬¾ÍÊÇc compiler¡£
CCÊǶÔc++±àÒëÆ÷µÄ½Ð·¨£¬ÕâÁ½¸öÃû³Æ¶¼²»ÌØָijһ³§¼ÒµÄ²úÆ·¡£ÀýÈçHPÌṩµÄHP-UXÉÏc±àÒëÆ÷½Ðcc£¬SolarisÉÏ
µÄc±àÒëÆ÷Ò²½Ðcc
ld means link editor£¬ÊÇÁ¬½ÓÆ÷µÄͨ³Æ£¬²¢²»ÌØָijһ¸ö¾ßÌåµÄ²úÆ·¡£µ«ÊÇËûÃǶ¼ÊÇÓÃÀ´Á¬½ÓÄ¿±êÎļþµÄ¡£
make means ???£¬make³ÌÐò¸ù¾ÝMakefile/makefileÖÐÖ¸¶¨µÄ¹æÔò£¬ÒÔ¼°Ò»Ð©Ä¬ÈϵĹæÔò£¬Íê³É´ÓÔ´´úÂëµ½×îÖÕ
´úÂëµÄ´¦Àí¹ý³Ì¡£²»¹â¿ÉÒÔÓÃÀ´±àÒëÁ¬½Ó³ÌÐò£¬Ò²¿ÉÒÔ×öÆäËüµÄһЩÓÐÒÀÀµ£¬·Ö½×¶ÎµÄÊÂÇé¡£
4. ÎÒÒѾ°²×°ÁËlinux£¬ÈçºÎ¿ªÊ¼ÎÒµÄC/C++Ö®ÂÃÄØ£¿
step 1: typein a helloworld program(1) in your favorate editor, I think it must be a vim
step 2: save your program to hello.c and then quit from the editor
step 3: typein 'gcc hello.c'
step 4: typein 'a.out'
Õâʱºò£¬ÄãÓ¦¸Ã¿ÉÒÔ¿´µ½ÄãµÄµÚÒ»¸ö³ÌÐòÒѾ˳ÀûÔËÐÐÁË£¡
ÎÒÃǽ«ÉÏÃæµÄËĸö²½Öè¸ÅÀ¨Ò»Ï£¬È»ºó×ñÑÕ⼸¸ö²½Ö裬Äã¾Í¿ÉÒÔ²»¶ÏµÄÉú²ú³ö¸÷ÑùµÄ³ÌÐòÁË
µÚÒ»²½£º±à¼³ÌÐò
µÚ¶þ²½£º±àÒë³ÌÐò
µÚÈý²½£ºÔËÐгÌÐò
5. ÎҵijÌÐòÔËÐнá¹ûÓëÎÒÏëÏóµÄ²»Í¬£¡
Èç¹ûÄãµÄµÚÒ»·´Ó¦ÊÇ"printfÕâ¸öº¯Êý£¨»òÕßgcc»òÕßÆäËûµÄ¿âʲôµÄ£©ÓÐÎÊÌ⣡"£¬ÄÇôÎÒÏëÄãÊǸö×ÔÁµ¿ñ£¬¼Çס£¬Õû¸ö
ϵͳÖÐΨһûÓо¹ý²âÊԵľÍÊÇÄãµÄ´úÂ룬Èκζ«Î÷¶¼ÊÇûÓÐÎÊÌâµÄ£¬³ýÁËÄãµÄ´úÂë¡££¨µ±È»gccÒ²¿ÉÄÜÓÐÎÊÌ⣬µ«ÊDZ»
ÄãÓöµ½µÄ¼¸ÂÊ¿ÉÒÔÔÝʱ¿´×÷ÊÇ0£©
ÎÒÃÇÓÐÁ½ÖÖ·½Ê½À´½â¾öÕâ¸öÎÊÌ⣺
µÚÒ»ÖÖ·½Ê½ÊÇʹÓÃprintfº¯ÊýÔÚ¿ÉÄܳöÎÊÌâµÄµØ·½Êä³öÏà¹Ø±äÁ¿£¬ºÃ´¦ÊÇ¿ÉÒÔ¿ìËÙµÄÉÏÊÖ£¬²»ÐèÒªÆäËûµÄ֪ʶ¡£»µ´¦ÊÇ
Èç¹ûÄãûÓÐ×ã¹»µÄ¼¼ÇÉ£¬ÄãÓпÉÄÜÍü¼Çɾ³ýÕâЩº¯Êý£¬ÒÔ¼°ÔÚ³ÌÐò±È½Ï´óµÄʱºòÿ´ÎÔö¼ÓÁËеÄprintf¶¼ÒªÖØбàÒ룬
Ì«ÀË·Ñʱ¼ä¡£
µÚ¶þÖÖ·½Ê½ÊÇʹÓõ÷ÊÔÆ÷£¬±ÈÈçgdb¡£µ«ÊÇgdb¾ÍÏóÄãÖªµÀµÄÆäËû´ó²¿·Öµ÷ÊÔÆ÷Ò
Ïà¹ØÎĵµ£º
ÊÔÌâ1£ºÇëдһ¸öCº¯Êý£¬Èô´¦ÀíÆ÷ÊÇBig_endianµÄ£¬Ôò·µ»Ø0£»ÈôÊÇLittle_endianµÄ£¬Ôò·µ»Ø1
½â´ð£º
int checkCPU( )
{
{
union w
{
&n ......
ÖØÒªµÄ¼¸µã£º
ÈκÎÒ»¸öÂß¼ÔËËã·ûµÄÓÅÏȼ¶µÍÓÚÈκÎÒ»¸ö¹ØϵÔËËã·û
ÒÆλÔËËã·ûµÄÓÅÏȼ¶Òª±ÈËãÊýÔËËã·ûµÍ£¬µ«±È¹ØϵÔËËã·û¸ß¡£
º¯Êýµ÷ÓÃÓÅÏȼ¶Òª¸ßÓÚµ¥Ä¿ÔËËã·ûµÄÓÅÏȼ¶¡£È磺pÊÇÒ»¸öº¯ÊýÖ¸Õ룬Ҫµ÷ÓÃpÖ¸ÏòµÄº¯Êý£¬ÐëΪ(*p)()£¬ÈôΪ*p()£¬Ôò±àÒëÆ÷»á½âÊͳÉ*(p())£¬¼´´Ëʱp()ÊÇÒ»¸öº¯Êý¡£ÀàÐÍת»»Êǵ¥Ä¿ÔËËã·û£¬½áºÏÐÔÊÇ×ÔÓ ......
1.ΪʲôÎÒдµÄMakefile£¬ÔÚ±à¼ÁËÔ´´úÂëÎļþºó£¬Ê¹ÓÃmake£¬makeÈ´ÌáʾĿ±êÎļþÒѾΪ×îеÄÁË£¡
2.OpenGL,ÔÚ´°¿ÚÖлµãʱ£¬ÔõÑùʹÓÃglVertexi()º¯Êý£¿ÒòΪ´«µÝµÄ²ÎÊýÈç¹ûÊÇ´óÓÚ1µÄintÐÍ£¬Ôò²»ÐУ¬¶ø±ØÐë´«µÝ[-0.1~0.1]Ö®¼äµÄfloat£¬¶øÇÒʹÓú¯Êý
gVertex2f().
3.OpenGL,ʹÓò˵¥Ê±£¬ÔõÑù½â¾öµã»÷²Ëµ¥ºó²»Òª²¶×½GLUT_UPÊ ......
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <stdio.h>
#include <netinet/in.h>
#include <arpa/inet.h>
int main(){
int sockfd;
int len;
struct sockaddr_in address;
int result;
char *strings="GET /svnup/rewrite.php HTTP/1 ......