Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

C±ê×¼¿âº¯ÊýabsµÄÒ»¸ö´íÎó

 0x80000000£¬¼´–2147483648ʱ,¶ÔËüÈ¡¸º»á²úÉúÉÏÒç
VC.NET 7.1 ÌṩµÄÈ¡¾ø¶ÔÖµº¯Êý(abs.cÖÐ)ÈçÏ£º
¡¡¡¡ int __cdecl abs ( int number)
¡¡¡¡ {
¡¡¡¡      return( number>=0 ? number : -number );
¡¡¡¡ }
¡¡¡¡ ´Ëº¯ÊýʵÏֵ÷dz£¼òµ¥£¬Õ§¿´Ö®ÏÂÎÞÈκÎ벡£¬¿ÉÊÇ×Ðϸ×ÁÄ¥×ÁÄ¥£¬¾Í·¢ÏÖÁËÒ»¸ö´ó©¶´¡£¾Ù¸ö¼«¶ËµÄÀý×Ó£¬µ±º¯Êý²ÎÊýΪINT_MIN(32λµÄint´ËֵΪ0x80000000£¬¼´–2147483648)ʱ,¶ÔËüÈ¡¸º»á²úÉúÉÏÒ磬ÒòΪ32λµÄintÄܱíʾµÄ×î´óÕýÊýÊÇINT_MAX(0x7fffffff£¬¼´2147483647)¡£Êµ¼ÊÉÏ£¬¶ÔINT_MINÈ¡¸ºµÈÓÚʲôҲûÓиÉ(0x80000000°´ÕÕ²¹ÂëÈ¡¸º¹æÔò»¹ÊÇ0x80000000)¡£ÒòΪº¯ÊýÉùÃ÷µÄ·µ»ØÖµÒ²ÊÇint£¬ËùÒÔ´ó¶àÊýʱºò³ÌÐòÔ±»áÓÃij¸öint±äÁ¿À´½ÓÊÕÕâ¸ö·µ»ØÖµ£¬µ«ÊÇÈçÉÏËùÊöµÄ¼«¶ËÇé¿öÔò¼¸ºõ°Ù·Ö°ÙµØµ¼Ö³ÌÐò»ìÂÒ¡£
¡¡¡¡ ¼òµ¥µÄ½â¾ö°ì·¨¾ÍÊÇ×ÜÊÇÓÃunsigned intÀàÐ͵ıäÁ¿À´½ÓÊÕ·µ»ØÖµ¡£ÒòΪ32λµÄunsigned intµÄÖµÓò·¶Î§ÊÇ0µ½4294967295(0xffffffff),2147483648ÂäÔÚÕâ¸ö·¶Î§ÄÚ£¬ËùÒÔÓÃunsigned int±äÁ¿¿ÉÒÔÕýÈ·µØ±í´ïINT_MINµÄ¾ø¶ÔÖµ¡£Èç¹û¾õµÃÕâÖÖ×ö·¨ÈÝÒ×Íü¼Ç£¬»¹¿ÉÒÔ×Ô¼ºÐ´Ò»¸öabs£¬Ö»ÐèÔÚÉÏÊöº¯ÊýÌåµÄÇ°Ãæ¼ÓÒ»¾äassert(number > INT_MIN)¾ÍÐÐÁË£¬»òÕß½«·µ»ØÖµ¸Ä³Éunsigned intÀàÐÍ¡£
¡¡¡¡ ΪʲôÔÚ±ê×¼¿âÖлá³öÏÖÕâôÒþ±ÎµÄ©¶´ÄØ£¿ÒòΪ¼ÆËã»úµÄ´æ´¢¿Õ¼äÓÐÏÞ£¬ËùÒÔCÖеÄÿÖÖÀàÐÍËùÕ¼×Ö½ÚÊýÒ²ÐëÊÇÓÐÏÞ´óС£¬ÕâÑù³ÌÐòÓïÑÔÖеÄÀàÐÍÕæÕýÄܱíʾµÄÖµÓò¾ÍÊǶÔÓ¦ÊýѧÀàÐÍÖµÓòµÄÓÐÏÞ×Ó¼¯ÁË¡£Õâ¾ÍÊÇÏÖʵÓëÀíÏëµÄ²î¾à¡£²»½öÈç´Ë£¬ÒòΪÓзûºÅÀàÐͱÈÎÞ·ûºÅÀàÐͶದ³öÒ»¸ö¶þ½øÖÆÎ»À´±íʾ·ûºÅÐÅÏ¢£¬ÔòËüÃÇÄܱíʾµÄÖµÓòÓÖÓÐËù²îÒì¡£µ«ÊdzÌÐòԱд³ÌÐòÈ´ÍùÍùÓÐÒâ»òÎÞÒâµØºöÂÔÕâÖÖ²î±ð£¬²»Ô¸Ãæ¶ÔÏÖʵ(ÕýÈçÓеijÌÐòÔ±µ÷Óú¯Êý´Ó²»¼ì²é·µ»ØÖµ)¡£ËûÃÇʹÓóÌÐòÖеÄÀàÐ;ÍÏóÔÚʹÓÃÀíÏëµÄÊýѧÉϵÄÀàÐÍÒ»Ñù¡£Å·ÖÞ°¢ÀïÑÇÄÉ»ð¼ý±¬Õ¨¾ÍÊÇ´ËÖÖ´íÎó¸øÎÒÃǵÄ×î²ÒÍ´½Ìѵ¡£
¡¡¡¡ ¼ÈÈ»Èç´Ë£¬Ã¿Ò»¸öC³ÌÐòÔ±¶¼ÓÐÔðÈÎÀμÇÕâôһÌõ¹æÔò:“¾­³£·´ÎÊ£ºÕâ¸ö±äÁ¿»ò±í´ïʽ»áÉÏÒç»òÏÂÒçÂ𣿔(¡¶±à³Ì¾«´â£­Microsoft±àдÓÅÖÊÎÞ´íC³ÌÐòÃØ¾÷¡·P80,Steve Maguire Öø)¡£
Àý×Ó:
#include <stdio.h>
int MyAbs(int number)
{
 return(number>=0 ? number :(-number));
}
void main()
{
 int number = 0x80000000;
 int absnumber = MyAbs(number);
 
 if(absnumber<0)
  pri


Ïà¹ØÎĵµ£º

LinuxÏÂCºÍC++¿ª·¢»ù´¡

LinuxÏÂCºÍC++¿ª·¢»ù´¡
»ù±¾±à³Ì¸ÅÄî
n ±à³ÌÓïÑÔ£ºC ¡¢C++
n ±àÒë(compile)£ºÔ´Îļþ£¨.c£©->Ä¿±êÎļþ(.o)
n Á¬½Ó(link)£ºÄ¿±êÎļþ(.o)->¿ÉÖ´ÐÐÎļþ
n ¿â(library)£º¾²Ì¬Á¬½Ó¿â(.a)¡¢¶¯Ì¬Á¬½Ó¿â(.so)
LinuxÏ¿ª·¢¹¤¾ß
n±à¼­Æ÷£ºvi¡¢emacs¡¢´°¿Ú±à¼­Æ÷
n±àÒëÆ÷£ºGCC
nµ÷ÊÔÆ÷£ºGDB
n¿ÉÖ´ÐÐÎļþ¹¤¾ß£ ......

C/C++Í·ÎļþÒ»ÀÀ

C¡¢´«Í³ C++
#include <assert.h>¡¡¡¡¡¡¡¡//É趨²åÈëµã
#include <ctype.h>¡¡¡¡¡¡¡¡ //×Ö·û´¦Àí
#include <errno.h>¡¡¡¡¡¡¡¡ //¶¨Òå´íÎóÂë
#include <float.h>¡¡¡¡¡¡¡¡ //¸¡µãÊý´¦Àí
#include <fstream.h>¡¡¡¡¡¡ //ÎļþÊäÈ룯Êä³ö
#include <iomanip.h>¡¡¡¡¡¡ //²ÎÊý»¯ÊäÈ룯Êä³ ......

CÓëC++ÖÐ×Ö·ûÖ¸Õë´¦Àí×Ö·û´®

¶¨ÒåÒ»¸ö×Ö·ûÖ¸Õ룬Æä±¾ÖʵĴ¦Àí·½Ê½Êǰ´×Ö·ûÊý×é´¦ÀíµÄ£¬ÔÚÄڴ濪±ÙÒ»¸ö×Ö·ûÊý×éÓÃÀ´´æ·Å×Ö·û´®³£Á¿£¬ÕâÑù±Ø¶¨»áÖÕÖ¹·û¡£¶øÕâÑùµÄÌØÐÔÒ²½ö¶ÔÓÚ×Ö·ûÖ¸Õë±äÁ¿¡£
ÔÚCÓïÑÔÖУ¬Í¨¹ýÊý×éÃû»òÕßÖ¸Õë±äÁ¿Êä³öÒ»¸ö×Ö·û´®£¬ÎÒÀí½âΪÁ½¸ö£º×Ö·û´®ÖÕÖ¹·ûµÄ´æÔÚ£»ÒÔ%s¸ñʽµÄÊä³ö·½Ê½¡£
char *p="I love china!";
   & ......

cÁ´±íʾÀý

CºêʵÀý
Õª×ÔLinuxÄÚºË2.6.21.5Ô´Âë(²¿·Ö)£¬Õ¹Ê¾ÁËÁ´±íµÄÁíÒ»ÖÖʵÏÖ˼·
δ²ÉÓÃANSI C±ê×¼£¬²ÉÓÃGNU C±ê×¼£¬×ñ´ÓGPL°æÈ¨Ðí¿É¡£
struct list_head {
struct list_head *next, *prev;
};

#define LIST_HEAD_INIT(name) { &(name), &(name) }

#define LIST_HEAD(name) \
struct list_ ......

dz̸CÓëC++µÄÉè¼ÆÓë±à³Ì·ç¸ñ£¨¶þ£©

ÉÏ´Î×ܽáÁËC++£¨ÃæÏò¶ÔÏó£©Éè¼ÆµÄºËÐÄ˼Ï룬²¢ÇÒÀý¾ÙÁËʹÓÃÀàÄ£ÐÍÀ´Ìæ´úifºÍswitchµÄÒ»ÖÖ½ÏΪµäÐ͵ÄÇé¿ö¡£ÏÂÃæÏëÀ´Ì¸Ì¸C++ÔÚ±àÂë·½ÃæµÄÌØµã¡£
ÔںܶྭµäµÄC++½Ì³ÌÖж¼ÓÐÒ»¸ö½¨Ò飺Ӧ¾¡Á¿Ê¹Óû§´úÂ루¿âµÄʹÓÃÕߣ©¿´ÆðÀ´¶ÌС¶ø¼òµ¥¡£°´ÕÕ³£Ê¶£¬¼òµ¥µÄ´úÂëͨ³£Òª±È´ó¶ÎµÄ´úÂëºÃÀí½â£¬¶øÓû§´úÂëͨ³£ÊµÏÖµÄÊÇ×îÉϲãµÄ¹¦ÄÜ»òÕ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ