Hacks in C Programming Language
ÏÂÃæÕâ¸ö³ÌÐòÊä³öʲô£¿
enum {false,true};
int main()
{
int i=1;
do
{
printf("%d\n",i);
i++;
if(i < 15)
continue;
}while(false);
return 0;
}
ÄãÏàÐÅô£¿ÏÂÃæÕâ¸ö³ÌÐòÊä³öµÄÁ½Ðж«Î÷²»Ò»Ñù£¡
#include <stdio.h>
#define f(a,b) a##b
#define g(a) #a
#define h(a) g(a)
int main()
{
printf("%s\n",h(f(1,2)));
printf("%s\n",g(f(1,2)));
return 0;
}
ÏÂÃæµÄ³ÌÐò¿´ËÆÍêÈ«ÕýÈ·¡£ÄãÄÜ¿´³öËüΪʲôͨ²»¹ý±àÒëÂð£¿
¿´³öÎÊÌâÇ°²»ÒªÈ¥ÊÔ×űàÒ룬²»È»Äã»áºó»ÚÄãû¿´³öÀ´Õâ¸öµÍ¼¶µÄÓï·¨´íÎó¡£
#include<stdio.h>
void OS_Solaris_print()
{
printf("Solaris - Sun Microsystems\n");
}
void OS_Windows_print()
{
printf("Windows - Microsoft\n");
}
void OS_HP-UX_print()
{
printf("HP-UX - Hewlett Packard\n");
}
int main()
{
int num;
printf("Enter the number (1-3):\n");
scanf("%d",&num);
switch(num)
{
case 1:
OS_Solaris_print();
break;
case 2:
OS_Windows_print();
break;
case 3:
OS_HP-UX_print();
break;
default:
printf("Hmm! only 1-3 :-)\n");
break;
}
return 0;
}
ΪʲôÏÂÃæÕâ¸ö³ÌÐòµÄÊä³ö²»ÊÇNONE£¿¿´Äã¶à¾Ã²ÅÄÜ¿´³öÀ´¡£
#include<stdio.h>
int main()
{
int a=10;
switch(a)
{
case '1':
printf("ONE\n");
break;
case '2':
printf("TWO\n");
break;
Ïà¹ØÎĵµ£º
C/C++±ÊÊÔÌâϵÁÐ
Ô¤´¦ÀíÆ÷£¨Preprocessor£©
1. ÓÃÔ¤´¦ÀíÖ¸Áî#define ÉùÃ÷Ò»¸ö³£Êý£¬ÓÃÒÔ±íÃ÷1ÄêÖÐÓжàÉÙÃ루ºöÂÔÈòÄêÎÊÌ⣩
#define SECONDS_PER_YEAR (60 * 60 * 24 * 365)UL
ÎÒÔÚÕâÏë¿´µ½¼¸¼þÊÂÇ飺
1). #define Óï·¨µÄ»ù±¾ÖªÊ¶£¨ÀýÈ磺²»ÄÜÒԷֺŽáÊø£¬À¨ºÅµÄʹÓ㬵ȵȣ©
2). ¶®µÃÔ¤´¦ÀíÆ÷½«ÎªÄã¼ÆËã³ ......
ºÜÆæ¹Ö£¬ÒÔÇ°Ò»Ö±ÒÔΪC++ÊǼæÈÝCµÄ£¬µ«ÊÇ£¬½ñÌìÓÃlex&yaccÉú³ÉµÄC´úÂë¿ÉÓÃͨ¹ýGCCµÄ±àÒ룬
µ«ÊÇÔõô¶¼Í¨²»¹ýG++µÄ±àÒ룬¶øÆä´íÎóºÜ¶à£¬ÓпÉÄÜÊÇlex&yaccÉú³ÉµÄC´úÂëÌ«ÀÏÁË£¬£¬£¬
ÎÒÊÇÕâÑù½â¾öµÄ
°Ñlex&yaccÉú³ÉµÄ´úÂë Óà GCC -c ±àÒë³É lex.o µÄÄ¿±êÎļþ¡£È»ºó g++ main.cpp lex.o ,¾ÍOKÁË
¼ÇµÃ£º ÔÚ main. ......
C
ÓïÑÔËùÓи´ÔÓµÄÖ¸ÕëÉùÃ÷£¬¶¼ÊÇÓɸ÷ÖÖÉùÃ÷ǶÌ×¹¹³ÉµÄ¡£ÈçºÎ½â¶Á¸´ÔÓÖ¸ÕëÉùÃ÷ÄØ£¿ÓÒ×ó·¨ÔòÊÇÒ»¸ö¼ÈÖøÃûÓÖ³£Óõķ½·¨¡£²»¹ý£¬ÓÒ×ó·¨ÔòÆäʵ²¢²»ÊÇC
±ê×¼ÀïÃæµÄÄÚÈÝ£¬ËüÊÇ´ÓC
±ê×¼µÄÉùÃ÷¹æ¶¨ÖйéÄɳöÀ´µÄ·½·¨¡£C
±ê×¼µÄÉùÃ÷¹æÔò£¬ÊÇÓÃÀ´½â¾öÈçºÎ´´½¨ÉùÃ÷µÄ£¬¶øÓÒ×ó·¨ÔòÊÇÓÃÀ´½â¾öÈçºÎ±çʶһ¸öÉùÃ÷µÄ£¬Á½Õß¿ ......
¸Ã³ÌÐòºÜ¼òµ¥£¬¾ÍÊÇÓÃC´ÓORACLE£¬°Ñµ±Ç°ÈÕÆÚÏÔʾ³öÀ´¾ÍOK£¬×÷Ϊһ¸ö¼òµ¥µÄDEMO
£¨Ò»£©Ð´PRO*C
/*===========================================================================
* pro*c±àÒë·½·¨£º
* Ô¤±àÒë proc test.pc
* ±àÒë gcc -o test test.c $ORACLE_HOME/lib/libclntsh.so
* ×÷Õß f ......