Sun Studio 12C

Size: px
Start display at page:

Download "Sun Studio 12C"

Transcription

1 Sun Studio 12C++ Sun Microsystems, Inc Network Circle Santa Clara, CA U.S.A

2 2007 Sun Microsystems, Inc Network Circle, Santa Clara, CA U.S.A. Sun Microsystems, Inc. / Sun Microsystems, Inc. FARFederal Acquisition Regulations Berkeley BSD UNIX X/Open Company, Ltd. / SunSun MicrosystemsSun Solaris Java docs.sun.comjava Solaris Sun Microsystems, Inc. / SPARC SPARC International, Inc. / SPARC Sun Microsystems, Inc. OPEN LOOK Sun TM Sun Microsystems, Inc. Sun Xerox Sun Xerox Xerox OPEN LOOK GUI Sun Sun / // @18135

3 C C Sun Studio 12 C x C C C SPARC V

4 Pragma #error C Shell CCFLAGS make C Sun Studio 12C++

5 C enum enum enum struct func

6 Sun Studio 12C++

7 instances=extern Setjmp/Longjmp const_cast reinterpret_cast static_cast void*

8 C C iostream MT iostream iostream C C C C C iostream complex C C Sun Studio 12C++

9 C C C STLport STLport iostream iostream iostream iostream iostream iostream char* iostream stdio iostream fstream iostream strstream: iostream stdio stdiobuf: iostream streambuf streambuf

10 streambuf iostream iostream complex complex CAPI dlopen C C A C A A A A Sun Studio 12C++

11 A.2.3 a A.2.4 Bbinding A.2.5 c A.2.6 cg{89 92} A.2.7 compat[={ 4 5}] A.2.8 +d A.2.9 -Dname[ =def] A.2.10 d{y n} A.2.11 dalign A.2.12 dryrun A.2.13 E A e{0 1} A erroff[= t] A errtags[= a] A errwarn[= t] A.2.18 fast A.2.19 features=a[,a...] A filt[= filter[,filter...]] A.2.21 flags A fma[={none fused}] A.2.23 fnonstd A.2.24 fns[={yes no}] A.2.25 fprecision=p A.2.26 fround=r A.2.27 fsimple[= n] A.2.28 fstore A.2.29 ftrap= t[,t...] A.2.30 G A.2.31 g A.2.32 g A.2.33 H A.2.34 h[]name A.2.35 help A Ipathname A I A.2.38 i

12 A inline A.2.40 instances=a A.2.41 instlib=filename A.2.42 KPIC A.2.43 Kpic A.2.44 keeptmp A.2.45 Lpath A.2.46 llib A.2.47 libmieee A.2.48 libmil A library=l[,l...] A m32 -m A mc A.2.52 migration A.2.53 misalign A mr[, string] A.2.55 mt A.2.56 native A.2.57 noex A.2.58 nofstore A.2.59 nolib A.2.60 nolibmil A.2.61 noqueue A.2.62 norunpath A.2.63 O A.2.64 Olevel A.2.65 o filename A p A.2.67 P A.2.68 p A.2.69 pentium A.2.70 pg A PIC A.2.72 pic A.2.73 pta A.2.74 ptipath Sun Studio 12C++

13 A.2.75 pto A.2.76 ptr A.2.77 ptv A.2.78 Qoption phase option[,option ] A.2.79 qoption phase option A.2.80 qp A.2.81 Qproduce sourcetype A.2.82 qproduce sourcetype A.2.83 Rpathname[ :pathname ] A.2.84 readme A.2.85 S A.2.86 s A.2.87 sb A.2.88 sbfast A staticlib=l[,l ] A sync_stdio=[yes no] A.2.91 temp=path A.2.92 template=opt[,opt ] A.2.93 time A.2.94 Uname A.2.95 unroll=n A.2.96 V A.2.97 v A.2.98 vdelx A.2.99 verbose=v[,v ] A w A w A w A Xm A xa A xalias_level[= n] A xar A xarch=isa A xautopar A xbinopt={prepare off} A xbuiltin[={ %all %none}]

14 A xcache=c A xcg[89 92] A xchar[= o] A xcheck[= i] A xchip=c A xcode=a A xcrossfile[= n] A xdebugformat=[stabs dwarf] A xdepend=[yes no] A xdumpmacros[= value[,value...]] A xe A xf[=v[, v...]] A xhelp=flags A xhelp=readme A xhwcprof A xia A xinline[= func_spec[,func_spec...]] A xinstrument=[ no%]datarace A xipo[={0 1 2}] A xipo_archive=[a] A xjobs=n A xlang=language[,language] A xldscope={v} A xlibmieee A xlibmil A xlibmopt A xlic_lib=sunperf A xlicinfo A xlinkopt[= level] A xm A xm A xmerge A xmaxopt[=v] A xmemalign=ab A xmodel=[a] A xnolib Sun Studio 12C++

15 A xnolibmil A xnolibmopt A xnorunpath A xolevel A xopenmp[= i] A xpagesize=n A xpagesize_heap=n A xpagesize_stack=n A xpch=v A xpchstop=file A xpg A xport64[=(v )] A xprefetch[= a[,a...]] A xprefetch_auto_type=a A xprefetch_level[= i] A xprofile=p A xprofile_ircache[= path] A xprofile_pathmap A xregs=r[,r...] A xrestrict[= f] A xs A xsafe=mem A xsb A xsbfast A xspace A xtarget=t A xthreadvar[= o] A xtime A xtrigraphs[={ yes no}] A xunroll=n A xustr={ascii_utf16_ushort no} A xvector[= a] A xvis[={yes no}] A xwe A Yc,path A z[]arg

16 B Pragma B.1 Pragma B.1.1 pragma B.2 Pragma B.2.1 #pragma align B.2.2 #pragma does_not_read_global_data B.2.3 #pragma does_not_return B.2.4 #pragma does_not_write_global_data B.2.5 #pragma dumpmacro s B.2.6 #pragma end_dumpmacros B.2.7 #pragma fini B.2.8 #pragma hdrstop B.2.9 #pragma ident B.2.10 #pragma init B.2.11 #pragma no_side_effect B.2.12 #pragma opt B.2.13 #pragma pack( n) B.2.14 #pragma rarely_called B.2.15 #pragma returns_new_memory B.2.16 #pragma unknown_control_flow B.2.17 #pragma weak Sun Studio 12C++

17 gcount I/O I/O MT iostream string A 1 foo.cc A 2 -E foo.cc A

18 18

19 Sun TM Studio 12 C++ C++ Solaris TM UNIX C C++ 4 C C C++ 14 iostream A C++ B C++ pragma 19

20 P 1 AaBbCc123 AaBbCc123 AaBbCc123 AaBbCc123.login ls -a % You have mail. % su Password: rm filename class 6 P 2 [] {} O[n] d{y n} O4, O dy " " "-" B{dynamic static} Bstatic : Rdir[:dir] R/local/libs:/U/a xinline=f1[, fn] xinline=alpha,dos 20 Sun Studio 12C++

21 Shell Shell C shell C shell Bourne shellkorn shell GNU Bourne-Again shell Bourne shellkorn shell GNU Bourne-Again shell machine-name% machine-name# $ # Sun Studio SPARC x86 UltraSPARC SPARC64AMD64Pentium Xeon EM64T Solaris x86 "x86" x86 "x64" AMD64 EM64T x86 x86 32 Sun Studio Solaris file:/opt/sunwspro/docs/index.html Linux file:/opt/sun/sunstudio12/docs/index.html /opt Solaris /opt/sun Linux docs.sun.com sm Web Solaris C++ C++ 21

22 Tools.h++ Tools.h++ Solaris Linux docs.sun.com Web IDE IDE Internet docs.sun.com Web ( Sun Microsystems Sun Web Sun Sun /opt C++ C++ Tools.h++ Tools.h++ HTML HTML Solaris (file:/opt/sunwspro/docs/index.html) HTML Sun Developer Network sunstudio/documentation/ss12 22 Sun Studio 12C++

23 HTML Solaris file:/opt/sunwspro/docs/index.html Linux file:/opt/sun/sunstudio12/docs/index.html HTML IDE HTML Sun Studio file:/opt/sunwspro/docs/index.html /opt C C++ Fortran Fortran OpenMP API ISO/IEC 9899:1999 C99 pragma lint C++ pragma Solaris Fortran / Fortran OpenMP API 23

24 C++ C++ C++ c++filt dem fbe fpversion gprof inline lex rpcgen sigfpe stdarg varargs version yacc C++ C++ CPU FPU C/C++ RPC SIGFPE LALR(1) Solaris docs.sun.com Web Solaris Reference Manual Collection Solaris Software Developer Collection Solaris Solaris 24 Sun Studio 12C++

25 Sun Developer Network Sun Studio ( Sun Studio Sun Developer Network Web ( C++ Bjarne Stroustrup The C++ Programming Language Addison-Wesley 1997 Nicolai Josuttis The C++ Standard LibraryAddison-Wesley 1999 Matthew Austern Generic Programming and the STLAddison-Wesley 1999 Angelika Langer Klaus Kreft Standard C++ IOStreams and Locales Addison-Wesley 2000 Bruce Eckel Thinking in C++, Volume 1, Second EditionPrentice Hall 2000 Margaret A. Ellis Bjarne Stroustrup The Annotated C++ Reference Manual Addison-Wesley 1990 Erich GammaRichard HelmRalph Johnson John Vlissides Design Patterns: Elements of Reusable Object-Oriented SoftwareAddison-Wesley 1995 Stanley B. Lippman Josee Lajoie C++ PrimerAddison-Wesley 1998 Scott Meyers Effective C++50 Ways to Improve Your Programs and DesignsAddison-Wesley

26 Scott Meyers More Effective C++35 Ways to Improve Your Programs and DesignsAddison-Wesley 1996 Sun URL Sun Sun URL Sun Sun Studio 12C++

27 1 C++ 27

28 28

29 1 1 C Sun Studio 12 C C C Sun Studio 12 C Sun Studio 12 C C Linux x86 x64 C Service Pack 3 SuSE Linux Enterprise Server 9 Red Hat Enterprise Linux Linux -m32 -m64 -xarch -xtarget -xchip UltraSPARC T2 SPARC64vi -fma=fused x86 SPARC (-xprefetch=explicit) 29

30 1.1 Sun Studio 12 C A xarch=isa 32 ILP32 64 LP A m32 -m64 ILP32 C intlong 32 LP64 long 64 Solaris Linux OS LP64 -m64 64 Solaris OS Linux OS 64 UltraSPARC(R) x Solaris Linux OS x86 x86 Solaris Sun pragma x86 OpenMP OpenMP Sun Studio 12: OpenMP API User s Guide -xarch ssesse2sse2a sse3 Solaris 9 4/04 Solaris OS Pentium 4 SSE/SSE2 Solaris OS SSE/SSE2 Solaris OS -xarch -xarch x86 SPARC x fstore x-arch=sse2 SSE2 Solaris Linux sin(x) Sun Studio 11 Solaris 10 OS -xarch Solaris Sun Studio 12C++

31 1.3 C++ -xarch SSESSE2SSE2a SSE3.il asm() 1.2 C++ (CC) C++ ISO ISO IS 14882:1998C++ SPARC TM SPARC V8 SPARC V9 UltraSPARC TM Prentice-Hall for SPARC International 8 (ISBN ) 9 (ISBN ) SPARC Architecture Manual C++ Sun C C++ C++ C++ example% CC -xhelp=readme HTML Netscape Communicator4.0 /opt/sunwspro/docs/index.html 1 C++ 31

32 1.4 C++ /opt HTML 1.4 (man) example% man topic C++ CC(1) man CC man -s ieee_flags(3m) example% man -s 3M ieee_flags 1.5 C++ C++ UNIX UNIX lex yacc C prof gprof tcov UNIX Program Performance Analysis Tools 1.6 C++ C++ C++ ASCII 8 C++ C++ 32 Sun Studio 12C++

33 1.6 C++ UNIX (Extended UNIX Characte, EUC) ascii "/" "/" 1 C++ 33

34 34

35 2 C++ C++ C++ C++ (.o) (.a) xar (.so) (-g) (-pg) 2.1 C++ C dlopen C C++ CC C++ 1. C example% cat greetings.cc #include <iostream> int main() { 35

36 2.2 std::cout << Real programmers write C++! << std::endl; return 0; } example% CC greetings.cc example% a.out Real programmers write C++! example% CC greetings.cc a.out a.out UNIX a.out -o example% CC o greetings greetings.cc -o greetings mv a.out example% greetings Real programmers write C++! example% CC CC [options] [source-files] [object-files] [libraries] ( ) (+) -features I -l L-library pti R-staticlib -U-verbose-xdumpmacros -xprefetch 36 Sun Studio 12C++

37 2.2 U D CC growth.c fft.c growth example% CC -g -o growth growth.c fft.c C++.c C++ C++.o.C C++.c.cc C++.c.cpp C++.c.cxx C++.c.c++ C++.c.i C++ C++.c.s.S C.il inline(1).o.a.so.so.n 2 C++ 37

38 C++ C C instances=extern C++ Template Database at./sunws_cache is incompatible with this compiler C C C C SunWS_cache) CCadmin -clean rm -rf SunWS_cache CC prgrm example% CC file1.cc file2.cc file3.cc -o prgrm file1.ofile2.o file3.o prgrm 38 Sun Studio 12C++

39 2.4 file1.ofile2.o file3.o.o.o.o c.o -c example% CC -c file1.cc Make new object file example% CC -o prgrm file1.o file2.o file3.o Make executable file "undefined external reference" B -compat fast -g -g0 -library -misalign -mt -p -xa -xarch xcg92 -xcg89 -xipo -xpagesize 2 C++ 39

40 2.4 -xpg -xprofile -xtarget -library-fast-xtarget -xarch -p-xpg -xprofile -g -g0 -g -g0 main -g -g0 -xcg92 -xtarget=ss1000 -xarch=v8 -xchip=super -xcache=16/64/4:1024/64/1 example% CC -c -xcg92 sbr.cc example% CC -c -xcg92 smain.cc example% CC -xcg92 sbr.o smain.o SPARCV9 64 V9 SPARC Solaris xarch=v9 xarch=v9a -xarch=v9b verbose ( ) (+) 40 Sun Studio 12C++

41 2.4 CC -bit (ld) ld -bit -b -i -t ld example% CC -bit move.cc < - -bit is not a recognized CC option CC: Warning: Option -bit passed to ld, if ld is invoked, ignored otherwise CC -fast example% CC fast move.cc < - The user meant to type -fast move.cc: ld: fatal: file fast: cannot open file; errno=2 ld: fatal: File processing errors. No output written to a.out C++ CC -v -dryrun C++ ccfe iropt SPARC -xo[2-5], -fast ir2hf x86 -xo[2-5], -fast inline SPARC.il ube_ipa x86 -xcrossfile=1 -xo4-xo5 -fast fbe cg SPARC ube x86 -xo[2-5], -fast 2 C++ 41

42 C++ CClink ld 2.5 C Pragma pragma C++ pragma C++ pragma 331 A z[]arg C++ #define #define identifier (...) replacement_list #define identifier (identifier_list,...) replacement_list VA_ARGS #define debug(...) fprintf(stderr, VA_ARGS ) #define showlist(...) puts(# VA_ARGS ) #define report(test,...) ((test)?puts(#test):\ printf( VA_ARGS )) debug(flag); debug(x = %d\n,x); showlist(the first, second, and third items.); report(x>y, x is%dbutyis%d, x,y); fprintf(stderr, Flag); fprintf(stderr, X = %d\n, x); puts(the first, second, and third items.); ((x>y)?puts(x>y):printf(x is%dbutyis%d, x, y)); 42 Sun Studio 12C++

43 #error 2.6 A 2 #ifdef +p sununixsparc i386 #error SPARC -xolevel swap -s swap(1m) swap example% swap -s total: 40236k bytes allocated k reserved = 47516k used, k available mkfile(1m) swap(1m) mkfile swap -a 2 C++ 43

44 2.6 example# mkfile -v 90m /home/swapfile /home/swapfile bytes example# /usr/sbin/swap -a /home/swapfile xo3 sh shell ulimit sh(1) 16M example$ ulimit -d csh shell limit csh(1) 16M example% limit datasize 16M 16M 32M sh shell example$ ulimit -d csh shell example% limit datasize 16M M 128M 44 Sun Studio 12C++

45 2.7 example% /usr/sbin/dmesg grep mem mem = K (0x ) avail mem = shell CCFLAGS make C Shell example% alias CCfx "CC -fast -xnolibmil" CCfx example% CCfx any.c CCfx example% CC -fast -xnolibmil any.c CCFLAGS CCFLAGS CCFLAGS CCFLAGS (C Shell) example% setenv CCFLAGS -xo2 -xsb CCFLAGS example% CC $CCFLAGS any.cc make CCFLAGS makefile make CC -xo2 -xsb files make make Sun make(1s) 2 C++ 45

46 make CCFLAGS makefile C++ make CCFLAGS Makefile makefile C++ C++.cpp SUFFIXES makefile SUFFIXES:.cpp.cpp~ makefile makefile.cpp: $(LINK.cc) -o $< $(LDLIBS).cpp~: $(GET) $(GFLAGS) -p $< > $*.cpp $(LINK.cc) -o $*.cpp $(LDLIBS).cpp.o: $(COMPILE.cc) $(OUTPUT_OPTION) $<.cpp~.o: $(GET) $(GFLAGS) -p $< > $*.cpp $(COMPILE.cc) $(OUTPUT_OPTION) $<.cpp.a: $(COMPILE.cc) -o $% $< $(COMPILE.cc) -xar $% $(RM) $%.cpp~.a: $(GET) $(GFLAGS) -p $< > $*.cpp $(COMPILE.cc) -o $% $< $(COMPILE.cc) -xar $% $(RM) $% make.h istreamfstream istream.ccfstream.cc 46 Sun Studio 12C++

47 3 C++ C dlopen C C E = Ipathname xunroll=4 o filename " " "-" 3.2 C++ llib liblib.a liblib.so llib 47

48 3.3 U D -features I -l L-library pti R-staticlib-U-verbose -xprefetch -D -D dlopen C C++ SPARC Solaris OS SPARC x86 Solaris OS x compat +e{0 1} g KPIC Kpic mt xcode=a xmerge xmodel (SPARC) (SPARC) Solaris x w +w2 +w 48 Sun Studio 12C++

49 xregs -z arg instlib -m32 -m64 -xinstrument xjobs xpch xpchstop xprofile_ircache xprofile_pathmap Thread Analyzer include -xpch include (SPARC) -xprofile=collect (SPARC) d C++ dryrun E C++ stdout 3 C++ 49

50 g g0 H keeptmp migration P.i Qoption readme README s temp=dir verbose=vlst -xcheck -xdumpmacros xe xhelp=flags xport64 xs xsb xsbfast (.o) dbx fma (SPARC) 50 Sun Studio 12C++

51 fns[={no yes}] fprecision=p fround=r fsimple=n fstore ftrap=tlst nofstore xlibmieee (SPARC) SPARC x86 IEEE x86 IEEE x86 libm IEEE compat features=alst -xchar xldscope xthreadvar -xtrigraphs xustr C++ char (SPARC) Bbinding d{y n} 3 C++ 51

52 G hname i ld(1) LD_LIBRARY_PATH Ldir llib library=llst mt norunpath Rplst staticlib=llst xar -xbuiltin[=opt] -xia -xlang=l[,l] xlibmieee xlibmil xlibmopt -xlic_lib=sunperf -xnativeconnect xnolib xnolibmil xnolibmopt dir liblib.a liblib.so C++ (SPARC) libm IEEE 754 libm (SPARC) Sun Performance Library TM C++-library=sunperf Java TM xlibmil 52 Sun Studio 12C++

53 xlic_lib=sunperf xlicinfo (SPARC) Sun Performance Library C++-library=sunperf library=%all noqueue -ptr -vdelx -xcg89 -xnativeconnect -xprefetch=yes -xprefetch=no -xtarget=ss2 -xprefetch=auto,explicit -xprefetch=no%auto,no%explicit c (.o) 3 C++ 53

54 dryrun E C++ stdout -erroff -errtags -errwarn -filt cc G H migration o filename filename P.i Qproduce sourcetype CC sourcetype s verbose=vlst +w w -xdumpmacros -xe xhelp=flags xhelp=readme xm xm1 README makefile /usr/include xsb xsbfast xtime 54 Sun Studio 12C++

55 xwe -z arg fast -fma (SPARC) -g s -m32 -m64 -xalias_level xarch=isa -xbinopt -xbuiltin[=opt] xcache=c xcg89 xcg92 xchip=c xf -xinline=flst -xipo xlibmil xlibmopt xlinkopt (SPARC) SPARC SPARC V8 libm (SPARC) 3 C++ 55

56 xmemalign=ab xnolibmil xnolibmopt xolevel xpagesize -xpagesize_heap -xpagesize_stack -xprefetch[=lst] -xprefetch_level xprofile xregs=rlst xsafe=mem xspace xtarget=t xthreadvar xunroll=n xvis (SPARC) xlibmil level (SPARC) -xprefetch=auto (SPARC) (SPARC) (SPARC) (SPARC) (SPARC) (SPARC) VIS TM Dname[=def] name E C++ stdout -H P.i 56 Sun Studio 12C++

57 Uname xm xm1 name makefile /usr/include p prof xa xpg xprofile gprof (SPARC) migration xhelp=flags xhelp=readme README H Ipathname pathname include 3 C++ 57

58 I- xm xm1 makefile /usr/include instances=a ptipath template=wlst mt xsafe=mem xthreadvar (SPARC) Allows no memory-based traps. (SPARC) 58 Sun Studio 12C++

59 2 C++ 59

60 60

61 4 331 A z[]arg -features=extensions C++ -features=extensions -features=extensions 4.1 mapfile -xldscope 286 A xldscope={v} 61

62 global symbolic hidden -Bsymbolic -Bsymbolic C++ symbolic ld(1) 4.2 global symbolic hidden C++ thread 325 A xthreadvar[= o] thread thread thread thread thread thread intx=4; thread int x = f(); std::string 62 Sun Studio 12C++

63 4.4 enum (&) 4.3 C++ -features=extensions 4.4 enum -features=extensions enum enum enum int -features=extensions enum E; // invalid: forward declaration of enum not allowed E e; // invalid: type E is incomplete enum enum enum 64 enum int

64 4.5 enum 4.5 enum -features=extensions enum -features=extensions typedef enum E F; // invalid, E is incomplete enum 4.6 enum enum enum enum E {e1, e2, e3}; int i = E::e1; // invalid: E is not a scope name -features=extensions -features=extensions enum E:: 4.7 struct typedef C++ -features=extensions struct struct -features=extensions union U { struct { int a; double b; }; // invalid: anonymous struct struct { char* c; unsigned d; }; // invalid: anonymous struct }; 64 Sun Studio 12C++

65 4.8 struct struct U Uu; u.a=1; struct union U { struct { int a; double b; }A; struct { char* c; unsigned d; }B; }; Uu; U.A.a = 1; 4.8 -features=extensions class C { public: C(int);... }; void f1(c*); int main() { f1(&c(2)); // invalid } C c(2); f1(&c); f1 4 65

66 class A { friend static void foo(<args>);... }; -features=extensions A "helper" foo foo 4.10 func -features=extensions func const char function-name static const char func [] = "function-name"; #include <stdio.h> void myfunc(void) { printf("%s\n", func ); } myfunc 66 Sun Studio 12C++

67 5 C++ C 5.1 C C C C++ C Kernighan Ritchie C (K&C)ANSI C Annotated Reference Manual C++ (ARM C++) ISO C++ C++ STDC cplusplus K&R C STDC ANSI C C++ K&R C ANSI C C++ #ifdef STDC int function(char*,...); #else int function(); #endif // C++ & ANSI C declaration // K&R C C cplusplus C++ 67

68 5.1 C++ c_plusplus cplusplus c_plusplus cplusplus C C++ extern "C" extern "C" #include extern "C" #include header.h... //... other include files... #if defined( cplusplus) extern C { #endif int g1(); int g2(); int g3() #if defined( cplusplus) } #endif ARM C++ cplusplus 1 ISO C L long ARM C++ ISO C++ // template function specialization #if cplusplus < L int power(int,int); #else template <> int power(int,int); #endif // ARM C++ // ISO C #ifndef HEADER_H #define HEADER_H /* contents of header file */ #endif 68 Sun Studio 12C++

69 main.cc template <class Number> Number twice(number original); template <class Number> Number twice(number original ) { return original + original; } int main() { return twice<int>(-3); } twice.h #ifndef TWICE_H #define TWICE_H template <class Number> Number twice(number original); template <class Number> Number twice( Number original ) { return original + original; } #endif main.cc #include twice.h int main() { return twice(-3); } twice.h 5 69

70 5.2 #ifndef TWICE_H #define TWICE_H template <class Number> Number twice(number original); #endif TWICE_H twice.cc template <class Number> Number twice( Number original ) { return original + original; } main.cc #include twice.h int main( ) { return twice<int>( -3 ); } typedef.c.c.cc.cpp.cxx.c Sun Studio 12C++

71 template <class Number> Number twice( Number original ); Number Number template <class Number> Number twice( Number original ) { return original + original; } 71

72 6.2 // Expressions with non-type template parameters // in the function parameter list are not supported template<int I> void foo( mytype<2*i> ) {... } template<int I, int J> void foo( int a[i+j] ) {... } double twicedouble( double item ) { return twice( item ); } template<class T> T func(); // no function arguments int k = func<int>(); // template argument supplied explicitly Array template <class Elem> class Array; String unsigned int template <unsigned Size> class String; Sun Studio 12C++

73 6.2 template <class Elem> class Array { Elem* data; int size; public: Array( int sz ); int GetSize(); Elem& operator[]( int idx ); }; template <unsigned Size> class String { char data[size]; static int overflows; public: String( char *initial ); int length(); }; class Elem unsigned Size Array template <class Elem> Array<Elem> template <class Elem> Array<Elem>::Array( int sz ) {size = sz; data = new Elem[size];} template <class Elem> int Array<Elem>::GetSize() { return size; } String 6 73

74 6.3 #include <string.h> template <unsigned Size> int String<Size>::length( ) {int len = 0; while (len < Size && data[len]!= \0 ) len++; return len;} template <unsigned Size> String<Size>::String(char *initial) {strncpy(data, initial, Size); if (length( ) == Size) overflows++;} template <unsigned Size> int String<Size>::overflows = 0; Array int_array Array Elem int Array<int> int_array(100); String short_string String<8> short_string("hello"); int x = int_array.getsize( ); int x = short_string.length( );. 6.3 Array<int> Array<double> Array<int> int Elem 74 Sun Studio 12C++

75 C template template float twice<float>(float original); template int twice(int original); template template class Array<char>; template class String<19>; template template int Array<char>::GetSize(); template int String<19>::length(); template template int String<19>::overflows; 6 75

76 C++ template <class Elem> void sort(array<elem>); template <class Elem> void sort(array<elem> store) {int num_elems = store.getsize(); for(inti=0; i<num_elems-1; i++) for (int j = i+1; j < num_elems; j++) if (store[j-1] > store[j]) {Elem temp = store[j]; store[j] = store[j-1]; store[j-1] = temp;}} Array Array<int> int_array(100); sort(int_array); // construct an array of ints // sort it template <class Elem = int> class Array; template <unsigned Size = 100> class String; twice sort twice sort 76 Sun Studio 12C++

77 6.6 template <> unsigned twice<unsigned>( unsigned original ); template <> sort<char*>(array<char*> store); template <> unsigned twice(unsigned original); template <> sort(array<char*> store); template <> unsigned twice<unsigned>(unsigned original) {return original << 1;} #include <string.h> template <> void sort<char*>(array<char*> store) {int num_elems = store.getsize(); for(inti=0; i<num_elems-1; i++) for (int j = i+1; j < num_elems; j++) if (strcmp(store[j-1], store[j]) > 0) {char *temp = store[j]; store[j] = store[j-1]; store[j-1] = temp;}} template<class T, class U> class A {...}; //primary template template<> class A<int, double> {...}; //specialization 6 77

78 6.7 template<class U> class A<int> {...}; // Example 1 template<class T, class U> class A<T*> {...}; // Example 2 template<class T> class A<T**, char> {...}; // Example 3 1 int 2 3 char converter intermediary temporary use1.cc use2.cc intermediary temporary use_common.h // Common template definition template <class Source, class Target> Target converter(source source) {temporary = (intermediary)source; return (Target)temporary;} use1.cc typedef int intermediary; int temporary; #include "use_common.h" use2.cc typedef double intermediary; unsigned int temporary; #include "use_common.h" 78 Sun Studio 12C++

79 6.7 cin cout cin cout array.h template <class Type> class Array { Type* data; int size; public: Array(int sz); int GetSize(); }; array.cc template <class Type> Array<Type>::Array(int sz) {size = sz; data = new Type[size];} template <class Type> int Array<Type>::GetSize() {return size;} file1.cc #include "array.h" struct Foo {int data;}; Array<Foo> File1Data(10); file2.cc #include "array.h" struct Foo {double data;}; Array<Foo> File2Data(20); file1.cc Foo file2.cc Foo operator<< 6 79

80 array.h // generates undefined error for the operator<< function #ifndef ARRAY_H #define ARRAY_H #include <iosfwd> template<class T> class array { int size; public: array(); friend std::ostream& operator<<(std::ostream&, const array<t>&); }; #endif array.cc #include <stdlib.h> #include <iostream> template<class T> array<t>::array() {size = 1024;} template<class T> std::ostream& operator<<(std::ostream& out, const array<t>& rhs) {return out << [ << rhs.size << ] ;} main.cc #include <iostream> #include "array.h" int main() { std::cout << "creating an array of int... " << std::flush; array<int> foo; std::cout << "done\n"; std::cout << foo << std::endl; return 0; } array friend friend ostream& operator<<(ostream&, const array<t>&); 80 Sun Studio 12C++

81 6.7 operator<< template class array operator<< type array<t> array<t> array.h #ifndef ARRAY_H #define ARRAY_H #include <iosfwd> // the next two lines declare operator<< as a template function template<class T> class array; template<class T> std::ostream& operator<<(std::ostream&, const array<t>&); template<class T> class array { int size; public: array(); friend std::ostream& operator<< <T> (std::ostream&, const array<t>&); }; #endif C++ typename typename struct simple { typedef int a_type; static int a_datum; }; int simple::a_datum = 0; // not a type template <class T> struct parametric { typedef T a_type; static T a_datum; }; template <class T> T parametric<t>::a_datum = 0; // not a type template <class T> struct example { static typename T::a_type variable1; // dependent static typename parametric<t>::a_type variable2; // dependent static simple::a_type variable3; // not dependent }; template <class T> typename T::a_type // dependent example<t>::variable1 = 0; // not a type template <class T> typename parametric<t>::a_type // dependent 6 81

82 6.7 example<t>::variable2 = 0; template <class T> simple::a_type example<t>::variable3 = 0; // not a type // not dependent // not a type ">>" ">" Array<String<10>> short_string_array(100); // >> = right-shift Array<String<10 >> short_string_array(100); Array<String<10> > short_string_array(100); C instances=extern make a.ccb.ccx.h x.cc -instances=extern... Makefile Sun Studio 12C++

83 6.7 CCC=CC all: a b a: b: $(CCC) -I. -instances=extern -c a.cc $(CCC) -instances=extern -o a a.o $(CCC) -I. -instances=extern -c b.cc $(CCC) -instances=extern -o b b.o clean: /bin/rm -rf SunWS_cache *.o a b... x.h... template <class T> class X { public: int open(); int create(); static int variable; };... x.cc... template <class T> int X<T>::create() { return variable; } template <class T> int X<T>::open() { return variable; } template <class T> int X<T>::variable = 1;... a.cc... #include "x.h" int main() { X<int> temp1; temp1.open(); 6 83

84 6.7 temp1.create(); }... b.cc... #include "x.h" int main() { X<int> temp1; } temp1.create(); a b make clean example% make a example% make b example% make a example% make clean example% make b 84 Sun Studio 12C++

85 7 7.1 C++ UNIX C++ -verbose=templatec++ -verbose=no%template+w 7.2 CCadmin(1) CCadmin clean ptclean

86 7.2 -template=wholeclass ISO C++ ISO C++ -template=wholeclass C++ C Sun C Sun Studio 12C++

87 instances=extern -instances=global -instance=extern dmake -instances=extern CC C++ CC xar ar example% CC xar -instances=extern o libmain.a a.o b.o c.o instance=extern -instances=extern.o.a.so dmake makefile 7 87

88 instances=static -instances=static -instances=global C dbx instances=static -g instances=global 88 Sun Studio 12C++

89 7.4 instances=explicit instances=semiexplicit SunWS_cache SUNWS_CACHE_NAME SUNWS_CACHE_NAME /sub/a.o./sub/SunWS_cache example% CC -o sub/a.o a.cc 7 89

90 /sub1/SunWS_cache./sub2/SunWS_cache./SunWS_cache example% CC sub1/a.o sub2/b.o ISO C instances=extern -instances=extern g g DDEBUG DEBUG template=no%extdef 90 Sun Studio 12C++

91 Cfront include foo() foo.h foo.cc.c.c.cc.cpp.cxx.c++ include I ptidirectory -pti -ptidirectory I ptidirectory I ptidirectory foo.h foo.cc foo.h foo C++.C.c.cc.cpp.cxx.c foo.cc.h.cc -template=no%extdef 7 91

92 92

93 8 C Bjarne Stroustrup The C++ Programming LanguageAddison-Wesley throw C terminate() abort() 93

94 features=no%except C++ dynamic_cast new 8.4 <exception> C++ -compat=5 <exception> // standard header <exception> namespace std { class exception { exception() throw(); exception(const exception&) throw(); exception& operator=(const exception&) throw(); virtual ~exception() throw(); virtual const char* what() const throw(); }; class bad_exception: public exception {...}; // Unexpected exception handling typedef void (*unexpected_handler)(); unexpected_handler set_unexpected(unexpected_handler) throw(); void unexpected(); // Termination handling typedef void (*terminate_handler)(); terminate_handler set_terminate(terminate_handler) throw(); void terminate(); bool uncaught_exception() throw(); } 94 Sun Studio 12C++

95 8.6 exception C++ exception what() C <exception.h> C++ C++ C++ <exception> <exception.h> // header <exception.h>, used for transition #include <exception> #include <new> using std::exception; using std::bad_exception; using std::set_unexpected; using std::unexpected; using std::set_terminate; using std::terminate; typedef std::exception xmsg; typedef std::bad_exception xunexpected; typedef std::bad_alloc xalloc; ( compat[=4]) <exception> <exception.h> C Setjmp/Longjmp setjmp/longjmp setjmp/longjmp A B A B longjmp longjmp try catch longjmp non-trivial 8.6 -Bsymbolic C++ -Bsymbolic dlopen RTLD_GLOBAL 8 95

96 96

97 9 C++ const_castreinterpret_cast static_cast dynamic_cast dynamic_cast<> _cast const_cast<int*>(v) (int*)v 9.1 const_cast const_cast<t>(v) const volatile const_cast<> const T class A { public: virtual void f(); int i; }; extern const volatile int* cvip; extern int* ip; void use_of_const_cast() { const A a1; 97

98 9.2 reinterpret_cast const_cast<a&>(a1).f(); ip = const_cast<int*> (cvip); } // remove const // remove const and volatile 9.2 reinterpret_cast reinterpret_cast<t>(v) v reinterpret_cast long C++ T1 T2 T1 T2 T1 T2 T1 X T2 Y reinterpret_cast const const_cast reinterpret_cast reinterpret_cast class A {int a; public: A();}; class B: public A {int b, c;}; void use_of_reinterpret_cast() { A a1; long l = reinterpret_cast<long>(&a1); A* ap = reinterpret_cast<a*>(l); // safe B* bp = reinterpret_cast<b*>(&a1); // unsafe const A a2; ap = reinterpret_cast<a*>(&a2); // error, const removed } 98 Sun Studio 12C++

99 static_cast static_cast<t>(v) v T void class B {...}; class C: public B {...}; enum E {first=1, second=2, third=3}; void use_of_static_cast(c* c1) { B* bp = c1; // implicit conversion C* c2 = static_cast<c*>(bp); // reverse implicit conversion int i = second; // implicit conversion E e = static_cast<e>(i); // reverse implicit conversion } static_cast const static_cast static_cast 9.4 (-compat[=4]) -f eatures=rtti T1 T2 T1 T2 T1 T2 dynamic_cast<t>(v) v T T cv void cv constvolatile const volatile T v static_cast<t>(v) 9 99

100 void* T void*v dynamic_cast<void*>(v) v void* void* v T T v T T T C++ std::bad_cast #include <assert.h> #include <stddef.h> // for NULL class A {public: virtual void f();}; class B {public: virtual void g();}; class AB: public virtual A, public B {}; void simple_dynamic_casts() { AB ab; B* bp = &ab; // no casts needed A* ap = &ab; AB& abr = dynamic_cast<ab&>(*bp); // succeeds ap = dynamic_cast<a*>(bp); assert(ap!= NULL); bp = dynamic_cast<b*>(ap); assert(bp!= NULL); ap = dynamic_cast<a*>(&abr); assert(ap!= NULL); bp = dynamic_cast<b*>(&abr); assert(bp!= NULL); } B #include <assert.h> #include <stddef.h> // for NULL #include <typeinfo> 100 Sun Studio 12C++

101 9.4 class A {public: virtual void f() {}}; class B {public: virtual void g() {}}; class AB: public virtual A, private B {}; void attempted_casts() { AB ab; B* bp = (B*)&ab; // C-style cast needed to break protection A* ap = dynamic_cast<a*>(bp); // fails, B is inaccessible assert(ap == NULL); try { AB& abr = dynamic_cast<ab&>(*bp); // fails, B is inaccessible } catch(const std::bad_cast&) { return; // failed reference cast caught here } assert(0); // should not get here } class AB_B: public AB, public B {}; class AB_B AB: public AB_B, public AB {}; void complex_dynamic_casts() { AB_B AB ab_b ab; A*ap = &ab_b ab; // okay: finds unique A statically AB*abp = dynamic_cast<ab*>(ap); // fails: ambiguous assert(abp == NULL); // STATIC ERROR: AB_B* ab_bp = (AB_B*)ap; // not a dynamic cast AB_B*ab_bp = dynamic_cast<ab_b*>(ap); // dynamic one is okay assert(ab_bp!= NULL); } dynamic_cast void using_dynamic_cast(a* ap) { if (AB *abp = dynamic_cast<ab*>(ap)) 9 101

102 9.4 { // abp is non-null, // so ap was a pointer to an AB object // go ahead and use abp process_ab(abp);} else { // abp is null, // so ap was NOT a pointer to an AB object // do not use abp process_not_ab(ap); } } (-compat[=4]) -features=rtti dynamic_cast static_cast dynamic_cast<t&> static_cast<t&> dynamic_cast Erich Gamma Design Patterns: Elements of Reusable Object-Oriented Software Addison-Wesley Sun Studio 12C++

103 10 C++ C++Tom Cargill C++ Programming StyleAddison-Wesley 1992Jon Louis Bentley Writing Efficient ProgramsPrentice-Hall 1982Dov Bulka David Mayhew Efficient C++: Performance Programming TechniquesAddison-Wesley 2000 Scott Meyers Effective C++ 50 Ways to Improve Your Programs and Designs Addison-Wesley 1998 C C++ C++ += + = a+b Tx=a+b; T x(a); x += b; 103

104 w switch try/catch 10.3 C 104 Sun Studio 12C++

105 10.4 C C++ Plain-Old-Data (POD) C++ C (-compat[=4])

106 C++ C C SPARC V7/V8 SPARC V9 x C++ this 106 Sun Studio 12C++

107 10.5 complex& operator*= (complex& left, complex& right) { left.real = left.real * right.real + left.imag * right.imag; left.imag = left.real * right.imag + left.image * right.real; } x*=x;

108 108

109 11 C++ iostream Tools.h++ C C++ mt D_REENTRANT l ld ( compat[=4]) mt libthread libc -mt libthread libcrun lthread libthread example% CC -c -mt myprog.cc example% CC -mt myprog.o example% CC -c -mt myprog.o example% CC myprog.o -lthread < -libthread is linked incorrectly ldd libthread 109

110 11.2 example% CC -mt myprog.cc example% ldd a.out libm.so.1 => /usr/lib/libm.so.1 libcrun.so.1 => /usr/lib/libcrun.so.1 libthread.so.1 => /usr/lib/libthread.so.1 libc.so.1 => /usr/lib/libc.so.1 libdl.so.1 => /usr/lib/libdl.so C++ C++ libcrunlibiostreamlibcstd libc iostream new delete 11.2 terminate() unexpected() set_terminate() set_unexpected() terminate() abort() pthread_cancel(3t) -noex -features=no%except pthread_cancel(3t) pthread_cleanup_push() 110 Sun Studio 12C++

111 11.3 C C++ C++ libcstd -library=cstd MT setlocale(3c) attributes(5) Rogue Wave copy on write C++ _RWSTDMutex _RWSTDGuard _RWSTDMutex void acquire() void release() class _RWSTDMutex { public: _RWSTDMutex (); ~_RWSTDMutex (); void acquire (); void release (); }; _RWSTDGuard _RWSTDMutex _RWSTDGuard std::exception on error ::thread_error class _RWSTDGuard { public: _RWSTDGuard (_RWSTDMutex&); ~_RWSTDGuard (); }; _RWSTD_MT_GUARD(mutex) _STDGUARD _RWSTDGuard

112 11.4 iostream #include <rw/stdmutex.h> // // An integer shared among multiple threads. // int I; // // A mutex used to synchronize updates to I. // _RWSTDMutex I_mutex; // // Increment I by one. Uses an _RWSTDMutex directly. // void increment_i () { I_mutex.acquire(); // Lock the mutex. I++; I_mutex.release(); // Unlock the mutex. } // // Decrement I by one. Uses an _RWSTDGuard. // void decrement_i () { _RWSTDGuard guard(i_mutex); // Acquire the lock on I_mutex. --I; // // The lock on I is released when destructor is called on guard. // } 11.4 iostream libc libiostream iostream (input-output, I/O) iostream C++ iostreamlibc libiostream libcstd iostream C Sun Studio 12C++

113 11.4 iostream iostream Solaris MT iostream C++ iostream MT libc MT MT MT MT iostream MT iostream iostream iostream iostream unsafe_ 11 1 iostream 11 1 iostream stream_mt streambuf unsafe_ios unsafe_istream unsafe_ostream unsafe_iostream streambuf streambuf unsafe_istream unsafe_ostream MT stream_mt MT streambuf unsafe_ class streambuf: public stream_mt {...}; class ios: virtual public unsafe_ios, public stream_mt {...}; class istream: virtual public ios, public unsafe_istream {...};

114 11.4 iostream stream_mt iostream MT MT I/O unsafe_ MT MT unsafe_ base MT unsafe_ base streambuf streambuf _unlocked iostream MT 11 2 char *oct_r (char *buf, int buflen, long num, int width) char *hex_r (char *buf, int buflen, long num, int width) char *dec_r (char *buf, int buflen, long num, int width) char *chr_r (char *buf, int buflen, long num, int width) ASCII ASCII ASCII chr ASCII chr width 114 Sun Studio 12C++

115 11.4 iostream 11 2 char *form_r (char *buf, int buflen, long num, sprintf format int width) libc iostream octhexdec chr form MT MT libc libc iostream -mt -D_REENTRANT -lthread -mt -lthread libc libthread -lthread iostream libc MT iostream iostream MT iostream iostream MT I/O 11 1 #include <iostream.h> enum iostate {IOok, IOeof, IOfail}; iostate read_number(istream& istr, int& num) { stream_locker sl(istr, stream_locker::lock_now);

116 11.4 iostream 11 1 istr >> num; } if (istr.eof()) return IOeof; if (istr.fail()) return IOfail; return IOok; stream_locker sl istream istr read_number sl istr MT gcount istream gcount gcount 11 2 gcount #include <iostream.h> #include <rlocks.h> void fetch_line(istream& istr, char* line, int& linecount) { stream_locker sl(istr, stream_locker::lock_defer); } sl.lock(); // lock the stream istr istr >> line; linecount = istr.gcount(); sl.unlock(); // unlock istr... stream_locker lock unlock I/O MT I/O I/O 11 3 I/O #include <rlocks.h> #include <iostream.h> class mystream: public istream { // other definitions Sun Studio 12C++

117 11.4 iostream 11 3 I/O }; int getrecord(char* name, int& id, float& gpa); int mystream::getrecord(char* name, int& id, float& gpa) { stream_locker sl(this, stream_locker::lock_now); *this >> name; *this >> id; *this >> gpa; } return this->fail() == 0; libc MT libc unsafe_ unsafe_ cout.unsafe_ostream::put( 4 ); cin.unsafe_istream::read(buf, len); unsafe_ cout cin unsafe_ unsafe cout cin 11 4 #include <iostream.h> //disable mt-safety cout.set_safe_flag(stream_mt::unsafe_object); //disable mt-safety cin.set_safe_flag(stream_mt::unsafe_object); cout.put(4 ); cin.read(buf, len); iostream MT iostream MT iostream MT

118 11.4 iostream 11 5 fs.set_safe_flag(stream_mt::unsafe_object);// disable MT-safety... do various i/o operations iostream iostream MT iostream MT iostream 11 6 generic_lock(); fs.set_safe_flag(stream_mt::unsafe_object);... do various i/o operations generic_unlock(); generic_lock generic_unlock / libc stream_locker iostream iostream MT libc 11 7 stream_mt stream_locker unsafe_ios unsafe_istream unsafe_ostream unsafe_iostream unsafe_fstreambase unsafe_strstreambase 118 Sun Studio 12C++

119 11.4 iostream iostream 11 8 class streambuf: public stream_mt {...}; class unsafe_ios {...}; class ios: virtual public unsafe_ios, public stream_mt {...}; class unsafe_fstreambase: virtual public unsafe_ios {...}; class fstreambase: virtual public ios, public unsafe_fstreambase {...}; class unsafe_strstreambase: virtual public unsafe_ios {...}; class strstreambase: virtual public ios, public unsafe_strstreambase {...}; class unsafe_istream: virtual public unsafe_ios {...}; class unsafe_ostream: virtual public unsafe_ios {...}; class istream: virtual public ios, public unsafe_istream {...}; class ostream: virtual public ios, public unsafe_ostream {...}; class unsafe_iostream: public unsafe_istream, public unsafe_ostream {...}; iostream 11 9 class streambuf { public: int sgetc_unlocked(); void sgetn_unlocked(char *, int); int snextc_unlocked(); int sbumpc_unlocked(); void stossc_unlocked(); int in_avail_unlocked(); int sputbackc_unlocked(char); int sputc_unlocked(int); int sputn_unlocked(const char *, int); int out_waiting_unlocked(); protected: char* base_unlocked(); char* ebuf_unlocked(); int blen_unlocked(); char* pbase_unlocked(); char* eback_unlocked(); char* gptr_unlocked(); char* egptr_unlocked(); char* pptr_unlocked(); void setp_unlocked(char*, char*);

120 11.4 iostream 11 9 void setg_unlocked(char*, char*, char*); void pbump_unlocked(int); void gbump_unlocked(int); void setb_unlocked(char*, char*, int); int unbuffered_unlocked(); char *epptr_unlocked(); void unbuffered_unlocked(int); int allocate_unlocked(int); }; class filebuf: public streambuf { public: int is_open_unlocked(); filebuf* close_unlocked(); filebuf* open_unlocked(const char*, int, int = filebuf::openprot); filebuf* attach_unlocked(int); }; class strstreambuf: public streambuf { public: int freeze_unlocked(); char* str_unlocked(); }; unsafe_ostream& endl(unsafe_ostream&); unsafe_ostream& ends(unsafe_ostream&); unsafe_ostream& flush(unsafe_ostream&); unsafe_istream& ws(unsafe_istream&); unsafe_ios& dec(unsafe_ios&); unsafe_ios& hex(unsafe_ios&); unsafe_ios& oct(unsafe_ios&); char* dec_r (char* buf, int buflen, long num, int width) char* hex_r (char* buf, int buflen, long num, int width) char* oct_r (char* buf, int buflen, long num, int width) char* chr_r (char* buf, int buflen, long chr, int width) char* str_r (char* buf, int buflen, const char* format, int width = 0); char* form_r (char* buf, int buflen, const char* format,...) 120 Sun Studio 12C++

121 11.4 iostream C++ iostream iostream.h, cout cincerr clog iostream MT iostream MT int c; cin.get(c); get ThreadA ThreadA get libc ThreadB ThreadA get get iostream I/O MT cout << " Error message:" << errstring[err_number] << "\n"; cout cout iostream libc stream_locker iostream stream_locker iostream

122 11.4 iostream thr_keycreate(3t) private iostream iostream iostream iostream iostream stream_locker iostream stream_locker iostream iostream stream_locker #include <fstream.h> #include <rlocks.h> void lock_example (fstream& fs) { const int len = 128; char buf[len]; int offset = 48; stream_locker s_lock(fs, stream_locker::lock_now);...// open file fs.seekg(offset, ios::beg); fs.read(buf, len); } stream_locker stream_locker ThreadA ThreadB 122 Sun Studio 12C++

123 11.4 iostream stream_locker I/O vbstream_locker lock unlock I/O { }... stream_locker file_lck(openfile_stream, stream_locker::lock_defer);... file_lck.lock(); // lock openfile_stream openfile_stream << "Value: " << int_value << "\n"; if(!openfile_stream) { file_error("output of value failed\n"); return; } file_lck.unlock(); // unlock openfile_stream stream_locker(3cc4) iostream MT MT MT stream_locker MT stream_locker streambuf _unlocked streambuf xsgetnunderflowpbackfailxsputnoverflowseekoff seekpos ios iword pword ios iword pword MT char

124 11.4 iostream iostream #include <fstream.h> #include <thread.h> fstream* fp; void *process_rtn(void*) { // body of sub-threads which uses fp... } void multi_process(const char* filename, int numthreads) { fp = new fstream(filename, ios::in); // create fstream object // before creating threads. // create threads for (int i=0; i<numthreads; i++) thr_create(0, STACKSIZE, process_rtn, 0, 0, 0);... // wait for threads to finish for (int i=0; i<numthreads; i++) thr_join(0, 0, 0); } delete fp; fp = NULL; // delete fstream object after // all threads have completed MT libc iostream 255 cout MT iostream // create tagged thread data // the output file is of the form: // <tag><string of data>\n 124 Sun Studio 12C++

125 11.4 iostream MT iostream // where tag is an integer value in a unsigned char. // Allows up to 255 threads to be run in this application // <string of data> is any printable characters // Because tag is an integer value written as char, // you need to use od to look at the output file, suggest: // od -c out.file more #include <stdlib.h> #include <stdio.h> #include <iostream.h> #include <fstream.h> #include <thread.h> struct thread_args { char* filename; int thread_tag; }; const int thread_bufsize = 256; // entry routine for each thread void* ThreadDuties(void* v) { // obtain arguments for this thread thread_args* tt = (thread_args*)v; char ibuf[thread_bufsize]; // open thread input file ifstream instr(tt->filename); stream_locker lockout(cout, stream_locker::lock_defer); while(1) { // read a line at a time instr.getline(ibuf, thread_bufsize - 1, \n ); if(instr.eof()) break; // lock cout stream so the i/o operation is atomic lockout.lock(); // tag line and send to cout cout << (unsigned char)tt->thread_tag << ibuf << "\n"; lockout.unlock(); } return 0; } int main(int argc, char** argv) { // argv: 1+ list of filenames per thread if(argc < 2) { cout << usage: " << argv[0] << " <files..>\n";

1991, 2010, Oracle / U.S. GOVERNMENT RIGHTS Programs, software, databases, and related documentation and technical data delivered to U.S. Government c

1991, 2010, Oracle / U.S. GOVERNMENT RIGHTS Programs, software, databases, and related documentation and technical data delivered to U.S. Government c Oracle Solaris Studio 12.2C++ 821 2509 2010 9 1991, 2010, Oracle / U.S. GOVERNMENT RIGHTS Programs, software, databases, and related documentation and technical data delivered to U.S. Government customers

More information

02

02 Thinking in C++: Volume One: Introduction to Standard C++, Second Edition & Volume Two: Practical Programming C++ C C++ C++ 3 3 C C class C++ C++ C++ C++ string vector 2.1 interpreter compiler 2.1.1 BASIC

More information

Sun Studio 11: C++ 用户指南

Sun Studio 11: C++ 用户指南 C++ 用 户 指 南 Sun Studio 11 Sun Microsystems, Inc. www.sun.com 文 件 号 码 819-4815-10 2005 年 1 月, 修 订 版 A 请 将 有 关 本 文 档 的 意 见 和 建 议 提 交 至 : http://www.sun.com/hwdocs/feedback 版 权 所 有 2005 Sun Microsystems,

More information

新版 明解C++入門編

新版 明解C++入門編 511!... 43, 85!=... 42 "... 118 " "... 337 " "... 8, 290 #... 71 #... 413 #define... 128, 236, 413 #endif... 412 #ifndef... 412 #if... 412 #include... 6, 337 #undef... 413 %... 23, 27 %=... 97 &... 243,

More information

C/C++ - 文件IO

C/C++ - 文件IO C/C++ IO Table of contents 1. 2. 3. 4. 1 C ASCII ASCII ASCII 2 10000 00100111 00010000 31H, 30H, 30H, 30H, 30H 1, 0, 0, 0, 0 ASCII 3 4 5 UNIX ANSI C 5 FILE FILE 6 stdio.h typedef struct { int level ;

More information

FY.DOC

FY.DOC 高 职 高 专 21 世 纪 规 划 教 材 C++ 程 序 设 计 邓 振 杰 主 编 贾 振 华 孟 庆 敏 副 主 编 人 民 邮 电 出 版 社 内 容 提 要 本 书 系 统 地 介 绍 C++ 语 言 的 基 本 概 念 基 本 语 法 和 编 程 方 法, 深 入 浅 出 地 讲 述 C++ 语 言 面 向 对 象 的 重 要 特 征 : 类 和 对 象 抽 象 封 装 继 承 等 主

More information

CC213

CC213 : (Ken-Yi Lee), E-mail: feis.tw@gmail.com 49 [P.51] C/C++ [P.52] [P.53] [P.55] (int) [P.57] (float/double) [P.58] printf scanf [P.59] [P.61] ( / ) [P.62] (char) [P.65] : +-*/% [P.67] : = [P.68] : ,

More information

C/C++ - 函数

C/C++ - 函数 C/C++ Table of contents 1. 2. 3. & 4. 5. 1 2 3 # include # define SIZE 50 int main ( void ) { float list [ SIZE ]; readlist (list, SIZE ); sort (list, SIZE ); average (list, SIZE ); bargragh

More information

2005 Sun Microsystems, Inc Network Circle, Santa Clara, CA U.S.A. Sun Sun Berkeley BSD UNIX X/Open Company, Ltd. / Sun Sun Microsystems Su

2005 Sun Microsystems, Inc Network Circle, Santa Clara, CA U.S.A. Sun Sun Berkeley BSD UNIX X/Open Company, Ltd. / Sun Sun Microsystems Su Java Desktop System Sun Microsystems, Inc. 4150 Network Circle Santa Clara, CA 95054 U.S.A. : 819 0675 10 2005 2 2005 Sun Microsystems, Inc. 4150 Network Circle, Santa Clara, CA 95054 U.S.A. Sun Sun Berkeley

More information

2004 Sun Microsystems, Inc Network Circle, Santa Clara, CA U.S.A. Sun Sun Berkeley BSD UNIX X/Open Company, Ltd. / SunSun MicrosystemsSun

2004 Sun Microsystems, Inc Network Circle, Santa Clara, CA U.S.A. Sun Sun Berkeley BSD UNIX X/Open Company, Ltd. / SunSun MicrosystemsSun SAP livecache Sun Cluster Solaris OS SPARC Sun Microsystems, Inc. 4150 Network Circle Santa Clara, CA 95054 U.S.A. : 817 7374 10 2004 4 A 2004 Sun Microsystems, Inc. 4150 Network Circle, Santa Clara, CA

More information

C/C++程序设计 - 字符串与格式化输入/输出

C/C++程序设计 - 字符串与格式化输入/输出 C/C++ / Table of contents 1. 2. 3. 4. 1 i # include # include // density of human body : 1. 04 e3 kg / m ^3 # define DENSITY 1. 04 e3 int main ( void ) { float weight, volume ; int

More information

c_cpp

c_cpp C C++ C C++ C++ (object oriented) C C++.cpp C C++ C C++ : for (int i=0;i

More information

Java Desktop System 呂衄盋 2 呂衄说柔

Java Desktop System 呂衄盋 2 呂衄说柔 Java Desktop System 2 Sun Microsystems, Inc. 4150 Network Circle Santa Clara, CA 95054 U.S.A. : 817 7767 10 2004 10 2004 Sun Microsystems, Inc. 4150 Network Circle, Santa Clara, CA 95054 U.S.A. Sun Sun

More information

新版 明解C言語入門編

新版 明解C言語入門編 328, 4, 110, 189, 103, 11... 318. 274 6 ; 10 ; 5? 48 & & 228! 61!= 42 ^= 66 _ 82 /= 66 /* 3 / 19 ~ 164 OR 53 OR 164 = 66 ( ) 115 ( ) 31 ^ OR 164 [] 89, 241 [] 324 + + 4, 19, 241 + + 22 ++ 67 ++ 73 += 66

More information

Sun Fire V440 Server Administration Guide - zh_TW

Sun Fire V440 Server Administration Guide - zh_TW Sun Fire V440 Server 管 理 指 南 Sun Microsystems, Inc. 4150 Network Circle Santa Clara, CA 95054 U.S.A. 650-960-1300 文 件 號 碼 :817-2818-10 2003 年 7 月, 修 訂 版 A 將 您 對 此 文 件 的 意 見 傳 送 到 :http://www.sun.com/hwdocs/feedback

More information

2004 Sun Microsystems, Inc Network Circle, Santa Clara, CA U.S.A. Sun Sun Berkeley BSD University of California UNIX X/Open Company, Ltd.

2004 Sun Microsystems, Inc Network Circle, Santa Clara, CA U.S.A. Sun Sun Berkeley BSD University of California UNIX X/Open Company, Ltd. Java Desktop System 2 Sun Microsystems, Inc. 4150 Network Circle Santa Clara, CA 95054 U.S.A. : 817 7758 10 2004 9 2004 Sun Microsystems, Inc. 4150 Network Circle, Santa Clara, CA 95054 U.S.A. Sun Sun

More information

2005 Sun Microsystems, Inc Network Circle, Santa Clara, CA U.S.A. Sun Sun Berkeley BSD UNIX X/Open Company, Ltd. / Sun Sun Microsystems Su

2005 Sun Microsystems, Inc Network Circle, Santa Clara, CA U.S.A. Sun Sun Berkeley BSD UNIX X/Open Company, Ltd. / Sun Sun Microsystems Su Linux Java Desktop System 3 Sun Microsystems, Inc. 4150 Network Circle Santa Clara, CA 95054 U.S.A. 819 1515 10 2005 8 2005 Sun Microsystems, Inc. 4150 Network Circle, Santa Clara, CA 95054 U.S.A. Sun

More information

2 2 3 DLight CPU I/O DLight Oracle Solaris (DTrace) C/C++ Solaris DLight DTrace DLight DLight DLight C C++ Fortran CPU I/O DLight AM

2 2 3 DLight CPU I/O DLight Oracle Solaris (DTrace) C/C++ Solaris DLight DTrace DLight DLight DLight C C++ Fortran CPU I/O DLight AM Oracle Solaris Studio 12.2 DLight 2010 9 2 2 3 DLight 3 3 6 13 CPU 16 18 21 I/O DLight Oracle Solaris (DTrace) C/C++ Solaris DLight DTrace DLight DLight DLight C C++ Fortran CPU I/O DLight AMP Apache MySQL

More information

ebook8-30

ebook8-30 3 0 C C C C C C++ C + + C++ GNU C/C++ GNU egcs UNIX shell s h e l l g a w k P e r l U N I X I / O UNIX shell awk P e r l U N I X C C C C C C U N I X 30.1 C C U N I X 70 C C U N I X U N I X U N I X C Dennis

More information

2007, Oracle / Sun Microsystems, Inc. / Sun Microsystems, Inc. FAR Federal Acquisition Regulations Berkeley BSD UNIX X/Open Company, Ltd. / Sun Sun Mi

2007, Oracle / Sun Microsystems, Inc. / Sun Microsystems, Inc. FAR Federal Acquisition Regulations Berkeley BSD UNIX X/Open Company, Ltd. / Sun Sun Mi Sun Studio 12 820 3035 2007 9 2007, Oracle / Sun Microsystems, Inc. / Sun Microsystems, Inc. FAR Federal Acquisition Regulations Berkeley BSD UNIX X/Open Company, Ltd. / Sun Sun Microsystems Sun Solaris

More information

Windows RTEMS 1 Danilliu MMI TCP/IP QEMU i386 QEMU ARM POWERPC i386 IPC PC104 uc/os-ii uc/os MMI TCP/IP i386 PORT Linux ecos Linux ecos ecos eco

Windows RTEMS 1 Danilliu MMI TCP/IP QEMU i386 QEMU ARM POWERPC i386 IPC PC104 uc/os-ii uc/os MMI TCP/IP i386 PORT Linux ecos Linux ecos ecos eco Windows RTEMS 1 Danilliu MMI TCP/IP 80486 QEMU i386 QEMU ARM POWERPC i386 IPC PC104 uc/os-ii uc/os MMI TCP/IP i386 PORT Linux ecos Linux ecos ecos ecos Email www.rtems.com RTEMS ecos RTEMS RTEMS Windows

More information

C/C++语言 - C/C++数据

C/C++语言 - C/C++数据 C/C++ C/C++ Table of contents 1. 2. 3. 4. char 5. 1 C = 5 (F 32). 9 F C 2 1 // fal2cel. c: Convert Fah temperature to Cel temperature 2 # include < stdio.h> 3 int main ( void ) 4 { 5 float fah, cel ;

More information

1 C++ 2 Bjarne Stroustrup C++ (system programming) 6 (infrastructure) C++ 7 Herb Sutter 8 C++ (efficiency) (flexibility) 9 (abstraction) (productivity

1 C++ 2 Bjarne Stroustrup C++ (system programming) 6 (infrastructure) C++ 7 Herb Sutter 8 C++ (efficiency) (flexibility) 9 (abstraction) (productivity 1 C++ 1 C++ Primer C++ (giantchen@gmail.com) 2012-7-11 Creative Commons - - 3.0 Unported (cc by-nc-nd) http://creativecommons.org/licenses/by-nc-nd/3.0/ 1 C++ 2009 Stanley Lippman C++ C++ Java/C#/Python

More information

1 LINUX IDE Emacs gcc gdb Emacs + gcc + gdb IDE Emacs IDE C Emacs Emacs IDE ICE Integrated Computing Environment Emacs Unix Linux Emacs Emacs Emacs Un

1 LINUX IDE Emacs gcc gdb Emacs + gcc + gdb IDE Emacs IDE C Emacs Emacs IDE ICE Integrated Computing Environment Emacs Unix Linux Emacs Emacs Emacs Un Linux C July 27, 2016 Contents 1 Linux IDE 1 2 GCC 3 2.1 hello.c hello.exe........................... 5 2.2............................... 9 2.2.1 -Wall................................ 9 2.2.2 -E..................................

More information

C++ 程式設計

C++ 程式設計 C C 料, 數, - 列 串 理 列 main 數串列 什 pointer) 數, 數, 數 數 省 不 不, 數 (1) 數, 不 數 * 料 * 數 int *int_ptr; char *ch_ptr; float *float_ptr; double *double_ptr; 數 (2) int i=3; int *ptr; ptr=&i; 1000 1012 ptr 數, 數 1004

More information

( CIP) /. :, ( ) ISBN TP CIP ( 2005) : : : : * : : 174 ( A ) : : ( 023) : ( 023)

( CIP) /. :, ( ) ISBN TP CIP ( 2005) : : : : * : : 174 ( A ) : : ( 023) : ( 023) ( CIP) /. :, 2005. 2 ( ) ISBN 7-5624-3339-9.......... TP311. 1 CIP ( 2005) 011794 : : : : * : : 174 ( A ) :400030 : ( 023) 65102378 65105781 : ( 023) 65103686 65105565 : http: / /www. cqup. com. cn : fxk@cqup.

More information

C/C++ - 字符串与字符串函数

C/C++ - 字符串与字符串函数 C/C++ Table of contents 1. 2. 3. 4. 1 char C 2 char greeting [50] = " How " " are " " you?"; char greeting [50] = " How are you?"; 3 printf ("\" Ready, go!\" exclaimed John."); " Ready, go!" exclaimed

More information

untitled

untitled 3 C++ 3.1 3.2 3.3 3.4 new delete 3.5 this 3.6 3.7 3.1 3.1 class struct union struct union C class C++ C++ 3.1 3.1 #include struct STRING { typedef char *CHARPTR; // CHARPTR s; // int strlen(

More information

2005 Sun Microsystems, Inc Network Circle, Santa Clara, CA U.S.A. Sun Sun Berkeley BSD UNIX X/Open Company, Ltd. / Sun Sun Microsystems Su

2005 Sun Microsystems, Inc Network Circle, Santa Clara, CA U.S.A. Sun Sun Berkeley BSD UNIX X/Open Company, Ltd. / Sun Sun Microsystems Su StarSuite 8 Sun Microsystems, Inc. 4150 Network Circle Santa Clara, CA 95054 U.S.A. 819 1344 10 2005 6 2005 Sun Microsystems, Inc. 4150 Network Circle, Santa Clara, CA 95054 U.S.A. Sun Sun Berkeley BSD

More information

int *p int a 0x00C7 0x00C7 0x00C int I[2], *pi = &I[0]; pi++; char C[2], *pc = &C[0]; pc++; float F[2], *pf = &F[0]; pf++;

int *p int a 0x00C7 0x00C7 0x00C int I[2], *pi = &I[0]; pi++; char C[2], *pc = &C[0]; pc++; float F[2], *pf = &F[0]; pf++; Memory & Pointer trio@seu.edu.cn 2.1 2.1.1 1 int *p int a 0x00C7 0x00C7 0x00C7 2.1.2 2 int I[2], *pi = &I[0]; pi++; char C[2], *pc = &C[0]; pc++; float F[2], *pf = &F[0]; pf++; 2.1.3 1. 2. 3. 3 int A,

More information

Microsoft Word - 物件導向編程精要.doc

Microsoft Word - 物件導向編程精要.doc Essential Object-Oriented Programming Josh Ko 2007.03.11 object-oriented programming C++ Java OO class object OOP Ruby duck typing complexity abstraction paradigm objects objects model object-oriented

More information

Learning Java

Learning Java Java Introduction to Java Programming (Third Edition) Prentice-Hall,Inc. Y.Daniel Liang 2001 Java 2002.2 Java2 2001.10 Java2 Philip Heller & Simon Roberts 1999.4 Java2 2001.3 Java2 21 2002.4 Java UML 2002.10

More information

ebook50-15

ebook50-15 15 82 C / C + + Developer Studio M F C C C + + 83 C / C + + M F C D L L D L L 84 M F C MFC DLL M F C 85 MFC DLL 15.1 82 C/C++ C C + + D L L M F C M F C 84 Developer Studio S t u d i o 292 C _ c p l u s

More information

Fun Time (1) What happens in memory? 1 i n t i ; 2 s h o r t j ; 3 double k ; 4 char c = a ; 5 i = 3; j = 2; 6 k = i j ; H.-T. Lin (NTU CSIE) Referenc

Fun Time (1) What happens in memory? 1 i n t i ; 2 s h o r t j ; 3 double k ; 4 char c = a ; 5 i = 3; j = 2; 6 k = i j ; H.-T. Lin (NTU CSIE) Referenc References (Section 5.2) Hsuan-Tien Lin Deptartment of CSIE, NTU OOP Class, March 15-16, 2010 H.-T. Lin (NTU CSIE) References OOP 03/15-16/2010 0 / 22 Fun Time (1) What happens in memory? 1 i n t i ; 2

More information

IO

IO 1 C/C++ C FILE* fscanf fgets fread fprintf fputs fwrite C++ ifstream ofstream >>

More information

untitled

untitled 1 Outline 數 料 數 數 列 亂數 練 數 數 數 來 數 數 來 數 料 利 料 來 數 A-Z a-z _ () 不 數 0-9 數 不 數 SCHOOL School school 數 讀 school_name schoolname 易 不 C# my name 7_eleven B&Q new C# (1) public protected private params override

More information

W. Richard Stevens UNIX Sockets API echo Sockets TCP OOB IO C struct C/C++ UNIX fork() select(2)/poll(2)/epoll(4) IO IO CPU 100% libevent UNIX CPU IO

W. Richard Stevens UNIX Sockets API echo Sockets TCP OOB IO C struct C/C++ UNIX fork() select(2)/poll(2)/epoll(4) IO IO CPU 100% libevent UNIX CPU IO Linux muduo C++ (giantchen@gmail.com) 2012-09-30 C++ TCP C++ x86-64 Linux TCP one loop per thread Linux native muduo C++ IT 5 C++ muduo 2 C++ C++ Primer 4 W. Richard Stevens UNIX Sockets API echo Sockets

More information

EK-STM32F

EK-STM32F STMEVKIT-STM32F10xx8 软 件 开 发 入 门 指 南 目 录 1 EWARM 安 装... 1 1.1 第 一 步 : 在 线 注 册... 1 1.2 第 二 步 : 下 载 软 件... 2 1.3 第 三 步 : 安 装 EWARM... 3 2 基 于 STMEVKIT-STM32F10xx8 的 示 例 代 码 运 行... 6 2.1 GPIO Demo... 6 2.2

More information

CC213

CC213 : (Ken-Yi Lee), E-mail: feis.tw@gmail.com 9 [P.11] : Dev C++ [P.12] : http://c.feis.tw [P.13] [P.14] [P.15] [P.17] [P.23] Dev C++ [P.24] [P.27] [P.34] C / C++ [P.35] 10 C / C++ C C++ C C++ C++ C ( ) C++

More information

C/C++语言 - 运算符、表达式和语句

C/C++语言 - 运算符、表达式和语句 C/C++ Table of contents 1. 2. 3. 4. C C++ 5. 6. 7. 1 i // shoe1.c: # include # define ADJUST 7. 64 # define SCALE 0. 325 int main ( void ) { double shoe, foot ; shoe = 9. 0; foot = SCALE * shoe

More information

Sun Update Connection System Sun Microsystems, Inc Network Circle Santa Clara, CA U.S.A

Sun Update Connection System Sun Microsystems, Inc Network Circle Santa Clara, CA U.S.A Sun Update Connection System 1.0.8 Sun Microsystems, Inc. 4150 Network Circle Santa Clara, CA 95054 U.S.A. 819 7286 10 2006 6 2006 Sun Microsystems, Inc. 4150 Network Circle, Santa Clara, CA 95054 U.S.A.

More information

Oracle Solaris Studio makefile C C++ Fortran IDE Solaris Linux C/C++/Fortran IDE "Project Properties" IDE makefile 1.

Oracle Solaris Studio makefile C C++ Fortran IDE Solaris Linux C/C++/Fortran IDE Project Properties IDE makefile 1. Oracle Solaris Studio 12.2 IDE 2010 9 2 8 9 10 11 13 20 26 28 30 32 33 Oracle Solaris Studio makefile C C++ Fortran IDE Solaris Linux C/C++/Fortran IDE "Project Properties" IDE makefile 1. "File" > "New

More information

C/C++ - 字符输入输出和字符确认

C/C++ - 字符输入输出和字符确认 C/C++ Table of contents 1. 2. getchar() putchar() 3. (Buffer) 4. 5. 6. 7. 8. 1 2 3 1 // pseudo code 2 read a character 3 while there is more input 4 increment character count 5 if a line has been read,

More information

2/80 2

2/80 2 2/80 2 3/80 3 DSP2400 is a high performance Digital Signal Processor (DSP) designed and developed by author s laboratory. It is designed for multimedia and wireless application. To develop application

More information

untitled

untitled A, 3+A printf( ABCDEF ) 3+ printf( ABCDEF ) 2.1 C++ main main main) * ( ) ( ) [ ].* ->* ()[] [][] ** *& char (f)(int); ( ) (f) (f) f (int) f int char f char f(int) (f) char (*f)(int); (*f) (int) (

More information

C C C The Most Beautiful Language and Most Dangerous Language in the Programming World! C 2 C C C 4 C 40 30 10 Project 30 C Project 3 60 Project 40

C C C The Most Beautiful Language and Most Dangerous Language in the Programming World! C 2 C C C 4 C 40 30 10 Project 30 C Project 3 60 Project 40 C C trio@seu.edu.cn C C C C The Most Beautiful Language and Most Dangerous Language in the Programming World! C 2 C C C 4 C 40 30 10 Project 30 C Project 3 60 Project 40 Week3 C Week5 Week5 Memory & Pointer

More information

ebook15-C

ebook15-C C 1 1.1 l s ( 1 ) - i i 4. 14 - d $ l s -ldi /etc/. /etc/.. - i i 3077 drwxr-sr-x 7 bin 2048 Aug 5 20:12 /etc/./ 2 drwxr-xr-x 13 root 512 Aug 5 20:11 /etc/../ $ls -ldi /. /..... i 2 2 drwxr-xr-x 13 root

More information

3.1 num = 3 ch = 'C' 2

3.1 num = 3 ch = 'C' 2 Java 1 3.1 num = 3 ch = 'C' 2 final 3.1 final : final final double PI=3.1415926; 3 3.2 4 int 3.2 (long int) (int) (short int) (byte) short sum; // sum 5 3.2 Java int long num=32967359818l; C:\java\app3_2.java:6:

More information

Sun StorEdge 3000 系列安装、操作和维护手册 (3310)

Sun StorEdge 3000 系列安装、操作和维护手册 (3310) Sun StorEdge 3000 系 列 安 装 操 作 和 维 护 手 册 Sun StorEdge 3310 SCSI 阵 列 Sun Microsystems, Inc. 4150 Network Circle Santa Clara, CA 95054 U.S.A. 650-960-1300 部 件 号 816-7960-11 2003 年 6 月, 修 订 版 A 有 关 本 文 档 的

More information

Eclipse C C++, or

Eclipse C C++,  or Eclipse C C++, Emailctchen@pl.csie.ntut.edu.tw or s1669021@ntut.edu.tw, s2598003@ntut.edu.tw http://pl.csie.ntut.edu.tw/~ctchen, http://www.ntut.edu.tw/~s2598003/ 2004/9/10 (0.02 ) Eclipse http://www.eclipse.org

More information

Microsoft Word - 11.doc

Microsoft Word - 11.doc 除 錯 技 巧 您 將 於 本 章 學 到 以 下 各 項 : 如 何 在 Visual C++ 2010 的 除 錯 工 具 控 制 下 執 行 程 式? 如 何 逐 步 地 執 行 程 式 的 敘 述? 如 何 監 看 或 改 變 程 式 中 的 變 數 值? 如 何 監 看 程 式 中 計 算 式 的 值? 何 謂 Call Stack? 何 謂 診 斷 器 (assertion)? 如 何

More information

C

C C 2017 3 14 1. 2. 3. 4. 2/95 C 1. 3/95 C I 1 // talkback.c: 2 #include 3 #include 4 #define DENSITY 62.4 5 int main(void) 6 { 7 float weight, volume; 8 int size; 9 unsigned long letters;

More information

How to Debug Tuxedo Server printf( Input data is: %s, inputstr); fprintf(stdout, Input data is %s, inputstr); fprintf(stderr, Input data is %s, inputstr); printf( Return data is: %s, outputstr); tpreturn(tpsuccess,

More information

untitled

untitled MPICH anzhulin@sohu.com 1 MPICH for Microsoft Windows 1.1 MPICH for Microsoft Windows Windows NT4/2000/XP Professional Server Windows 95/98 TCP/IP MPICH MS VC++ 6.x MS VC++.NET Compaq Visual Fortran 6.x

More information

新・明解C言語入門編『索引』

新・明解C言語入門編『索引』 !... 75!=... 48 "... 234 " "... 9, 84, 240 #define... 118, 213 #include... 148 %... 23 %... 23, 24 %%... 23 %d... 4 %f... 29 %ld... 177 %lf... 31 %lu... 177 %o... 196 %p... 262 %s... 242, 244 %u... 177

More information

Java Desktop System 2003 Sun Microsystems, Inc Network Circle Santa Clara, CA U.S.A. :

Java Desktop System 2003 Sun Microsystems, Inc Network Circle Santa Clara, CA U.S.A. : Java Desktop System 2003 Sun Microsystems, Inc. 4150 Network Circle Santa Clara, CA 95054 U.S.A. : 817 4572 10 2003 12 2003 Sun Microsystems, Inc. 4150 Network Circle, Santa Clara, CA 95054 U.S.A. Sun

More information

epub83-1

epub83-1 C++Builder 1 C + + B u i l d e r C + + B u i l d e r C + + B u i l d e r C + + B u i l d e r 1.1 1.1.1 1-1 1. 1-1 1 2. 1-1 2 A c c e s s P a r a d o x Visual FoxPro 3. / C / S 2 C + + B u i l d e r / C

More information

2013 C 1 #include <stdio.h> 2 int main(void) 3 { 4 int cases, i; 5 long long a, b; 6 scanf("%d", &cases); 7 for (i = 0; i < cases; i++) 8 { 9 scanf("%

2013 C 1 #include <stdio.h> 2 int main(void) 3 { 4 int cases, i; 5 long long a, b; 6 scanf(%d, &cases); 7 for (i = 0; i < cases; i++) 8 { 9 scanf(% 2013 ( 28 ) ( ) 1. C pa.c, pb.c, 2. C++ pa.cpp, pb.cpp Compilation Error long long cin scanf Time Limit Exceeded 1: A 10 B 1 C 1 D 5 E 5 F 1 G II 5 H 30 1 2013 C 1 #include 2 int main(void) 3

More information

华恒家庭网关方案

华恒家庭网关方案 LINUX V1.5 1 2 1 2 LINUX WINDOWS PC VC LINUX WINDOWS LINUX 90% GUI LINUX C 3 REDHAT 9 LINUX PC TFTP/NFS http://www.hhcn.com/chinese/embedlinux-res.html minicom NFS mount C HHARM9-EDU 1 LINUX HHARM9-EDU

More information

Important Notice SUNPLUS TECHNOLOGY CO. reserves the right to change this documentation without prior notice. Information provided by SUNPLUS TECHNOLO

Important Notice SUNPLUS TECHNOLOGY CO. reserves the right to change this documentation without prior notice. Information provided by SUNPLUS TECHNOLO Car DVD New GUI IR Flow User Manual V0.1 Jan 25, 2008 19, Innovation First Road Science Park Hsin-Chu Taiwan 300 R.O.C. Tel: 886-3-578-6005 Fax: 886-3-578-4418 Web: www.sunplus.com Important Notice SUNPLUS

More information

Microsoft PowerPoint - string_kruse [兼容模式]

Microsoft PowerPoint - string_kruse [兼容模式] Strings Strings in C not encapsulated Every C-string has type char *. Hence, a C-string references an address in memory, the first of a contiguous set of bytes that store the characters making up the string.

More information

nooog

nooog C : : : , C C,,, C, C,, C ( ), ( ) C,,, ;,, ; C,,, ;, ;, ;, ;,,,, ;,,, ; : 1 9, 2 3, 4, 5, 6 10 11, 7 8, 12 13,,,,, 2008 1 1 (1 ) 1.1 (1 ) 1.1.1 ( ) 1.1.2 ( ) 1.1.3 ( ) 1.1.4 ( ) 1.1.5 ( ) 1.2 ( ) 1.2.1

More information

WWW PHP

WWW PHP WWW PHP 2003 1 2 function function_name (parameter 1, parameter 2, parameter n ) statement list function_name sin, Sin, SIN parameter 1, parameter 2, parameter n 0 1 1 PHP HTML 3 function strcat ($left,

More information

C语言的应用.PDF

C语言的应用.PDF AVR C 9 1 AVR C IAR C, *.HEX, C,,! C, > 9.1 AVR C MCU,, AVR?! IAR AVR / IAR 32 ALU 1KBytes - 8MBytes (SPM ) 16 MBytes C C *var1, *var2; *var1++ = *--var2; AVR C 9 2 LD R16,-X ST Z+,R16 Auto (local

More information

Copyright 2003 Sun Microsystems, Inc Network Circle, Santa Clara, CA U.S.A.. Sun ( ) Sun Berkeley BSD UNIX / X/Open Company, Ltd. Sun Sun

Copyright 2003 Sun Microsystems, Inc Network Circle, Santa Clara, CA U.S.A.. Sun ( ) Sun Berkeley BSD UNIX / X/Open Company, Ltd. Sun Sun Java Desktop System 2003 Sun Microsystems, Inc. 4150 Network Circle Santa Clara, CA 95054 U.S.A. : 817 4573 10 2003 12 Copyright 2003 Sun Microsystems, Inc. 4150 Network Circle, Santa Clara, CA 95054 U.S.A..

More information

, 7, Windows,,,, : ,,,, ;,, ( CIP) /,,. : ;, ( 21 ) ISBN : -. TP CIP ( 2005) 1

, 7, Windows,,,, : ,,,, ;,, ( CIP) /,,. : ;, ( 21 ) ISBN : -. TP CIP ( 2005) 1 21 , 7, Windows,,,, : 010-62782989 13501256678 13801310933,,,, ;,, ( CIP) /,,. : ;, 2005. 11 ( 21 ) ISBN 7-81082 - 634-4... - : -. TP316-44 CIP ( 2005) 123583 : : : : 100084 : 010-62776969 : 100044 : 010-51686414

More information

新・解きながら学ぶC言語

新・解きながら学ぶC言語 330!... 67!=... 42 "... 215 " "... 6, 77, 222 #define... 114, 194 #include... 145 %... 21 %... 21 %%... 21 %f... 26 %ld... 162 %lf... 26 %lu... 162 %o... 180 %p... 248 %s... 223, 224 %u... 162 %x... 180

More information

概述

概述 OPC Version 1.6 build 0910 KOSRDK Knight OPC Server Rapid Development Toolkits Knight Workgroup, eehoo Technology 2002-9 OPC 1...4 2 API...5 2.1...5 2.2...5 2.2.1 KOS_Init...5 2.2.2 KOS_InitB...5 2.2.3

More information

C 1

C 1 C homepage: xpzhangme 2018 5 30 C 1 C min(x, y) double C // min c # include # include double min ( double x, double y); int main ( int argc, char * argv []) { double x, y; if( argc!=

More information

Microsoft Word - PS2_linux_guide_cn.doc

Microsoft Word - PS2_linux_guide_cn.doc Linux For $ONY PlayStatioin2 Unofficall General Guide Language: Simplified Chinese First Write By Beter Hans v0.1 Mail: hansb@citiz.net Version: 0.1 本 人 是 菜 鸟 + 小 白 欢 迎 指 正 错 误 之 处, 如 果 您 有 其 他 使 用 心 得

More information

Copyright 2006 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, California 95054, U.S.A. 版 權 所 有 Sun Microsystems, Inc. 對 於 本 文 件 所 述 技 術 擁 有

Copyright 2006 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, California 95054, U.S.A. 版 權 所 有 Sun Microsystems, Inc. 對 於 本 文 件 所 述 技 術 擁 有 Sun Management Center 3.6 版 本 5 附 加 軟 體 版 本 說 明 適 用 於 Sun Fire Sun Blade Netra 及 Sun Ultra 系 統 Sun Microsystems, Inc. www.sun.com 文 件 號 碼 820-0131-10 2006 年 10 月, 修 訂 版 A 請 將 您 對 本 文 件 的 意 見 提 交 至 :http://www.sun.com/hwdocs/feedback

More information

Oracle Solaris Studio 12.3 C E E

Oracle Solaris Studio 12.3 C E E Oracle Solaris Studio 12.3 C E26437 2011 12 E26437-01 1991, 2011, Oracle / U.S. GOVERNMENT END USERS: Oracle programs, including any operating system, integrated software, any programs installed on the

More information

EJB-Programming-3.PDF

EJB-Programming-3.PDF :, JBuilder EJB 2.x CMP EJB Relationships JBuilder EJB Test Client EJB EJB Seminar CMP Entity Beans Value Object Design Pattern J2EE Design Patterns Value Object Value Object Factory J2EE EJB Test Client

More information

第7章-并行计算.ppt

第7章-并行计算.ppt EFEP90 10CDMP3 CD t 0 t 0 To pull a bigger wagon, it is easier to add more oxen than to grow a gigantic ox 10t 0 t 0 n p Ts Tp if E(n, p) < 1 p, then T (n) < T (n, p) s p S(n,p) = p : f(x)=sin(cos(x))

More information

科学计算的语言-FORTRAN95

科学计算的语言-FORTRAN95 科 学 计 算 的 语 言 -FORTRAN95 目 录 第 一 篇 闲 话 第 1 章 目 的 是 计 算 第 2 章 FORTRAN95 如 何 描 述 计 算 第 3 章 FORTRAN 的 编 译 系 统 第 二 篇 计 算 的 叙 述 第 4 章 FORTRAN95 语 言 的 形 貌 第 5 章 准 备 数 据 第 6 章 构 造 数 据 第 7 章 声 明 数 据 第 8 章 构 造

More information

C PICC C++ C++ C C #include<pic.h> C static volatile unsigned char 0x01; static volatile unsigned char 0x02; static volatile unsigned cha

C PICC C++ C++ C C #include<pic.h> C static volatile unsigned char 0x01; static volatile unsigned char 0x02; static volatile unsigned cha CYPOK CYPOK 1 UltraEdit Project-->Install Language Tool: Language Suite----->hi-tech picc Tool Name ---->PICC Compiler Executable ---->c:hi-picinpicc.exe ( Command-line Project-->New Project-->File Name--->myc

More information

C/C++ 语言 - 循环

C/C++ 语言 - 循环 C/C++ Table of contents 7. 1. 2. while 3. 4. 5. for 6. 8. (do while) 9. 10. (nested loop) 11. 12. 13. 1 // summing.c: # include int main ( void ) { long num ; long sum = 0L; int status ; printf

More information

Microsoft Word - 01.DOC

Microsoft Word - 01.DOC 第 1 章 JavaScript 简 介 JavaScript 是 NetScape 公 司 为 Navigator 浏 览 器 开 发 的, 是 写 在 HTML 文 件 中 的 一 种 脚 本 语 言, 能 实 现 网 页 内 容 的 交 互 显 示 当 用 户 在 客 户 端 显 示 该 网 页 时, 浏 览 器 就 会 执 行 JavaScript 程 序, 用 户 通 过 交 互 式 的

More information

WebSphere Studio Application Developer IBM Portal Toolkit... 2/21 1. WebSphere Portal Portal WebSphere Application Server stopserver.bat -configfile..

WebSphere Studio Application Developer IBM Portal Toolkit... 2/21 1. WebSphere Portal Portal WebSphere Application Server stopserver.bat -configfile.. WebSphere Studio Application Developer IBM Portal Toolkit... 1/21 WebSphere Studio Application Developer IBM Portal Toolkit Portlet Doug Phillips (dougep@us.ibm.com),, IBM Developer Technical Support Center

More information

C 1 # include <stdio.h> 2 int main ( void ) { 4 int cases, i; 5 long long a, b; 6 scanf ("%d", & cases ); 7 for (i = 0;i < cases ;i ++) 8 { 9

C 1 # include <stdio.h> 2 int main ( void ) { 4 int cases, i; 5 long long a, b; 6 scanf (%d, & cases ); 7 for (i = 0;i < cases ;i ++) 8 { 9 201 201 21 ( ) 1. C pa.c, pb.c, 2. C++ pa.cpp, pb.cpp Compilation Error long long cin scanf Time Limit Exceeded 1: A 1 B 1 C 5 D RPG 10 E 10 F 1 G II 1 1 201 201 C 1 # include 2 int main ( void

More information

ebook39-5

ebook39-5 5 3 last-in-first-out, LIFO 3-1 L i n e a r L i s t 3-8 C h a i n 3 3. 8. 3 C + + 5.1 [ ] s t a c k t o p b o t t o m 5-1a 5-1a E D 5-1b 5-1b E E 5-1a 5-1b 5-1c E t o p D t o p D C C B B B t o p A b o

More information

_汪_文前新ok[3.1].doc

_汪_文前新ok[3.1].doc 普 通 高 校 本 科 计 算 机 专 业 特 色 教 材 精 选 四 川 大 学 计 算 机 学 院 国 家 示 范 性 软 件 学 院 精 品 课 程 基 金 青 年 基 金 资 助 项 目 C 语 言 程 序 设 计 (C99 版 ) 陈 良 银 游 洪 跃 李 旭 伟 主 编 李 志 蜀 唐 宁 九 李 涛 主 审 清 华 大 学 出 版 社 北 京 i 内 容 简 介 本 教 材 面 向

More information

ebook15-2

ebook15-2 2 U N I X 2.1 U N I X C U N I X U N I X 80 U N I X ( ) U N I X 2.2 UNIX 2.2.1 ANSI C 1989 C A N S I X 3. 159-1989 ANSI 1989 ISO/IEC 9899:1990 A N S I ( I S O ) ANSI C C UN I X C ANSI 1989 4 Plauger 1992;Kernighan

More information

Microsoft Word - 第3章.doc

Microsoft Word - 第3章.doc Java C++ Pascal C# C# if if if for while do while foreach while do while C# 3.1.1 ; 3-1 ischeck Test() While ischeck while static bool ischeck = true; public static void Test() while (ischeck) ; ischeck

More information

新・解きながら学ぶJava

新・解きながら学ぶJava 481! 41, 74!= 40, 270 " 4 % 23, 25 %% 121 %c 425 %d 121 %o 121 %x 121 & 199 && 48 ' 81, 425 ( ) 14, 17 ( ) 128 ( ) 183 * 23 */ 3, 390 ++ 79 ++ 80 += 93 + 22 + 23 + 279 + 14 + 124 + 7, 148, 16 -- 79 --

More information

RunPC2_.doc

RunPC2_.doc PowerBuilder 8 (5) PowerBuilder Client/Server Jaguar Server Jaguar Server Connection Cache Thin Client Internet Connection Pooling EAServer Connection Cache Connection Cache Connection Cache Connection

More information

Oracle Oracle Solaris Studio IDE makefile C C++ Fortran makefile IDE Solaris Linux C/C++/Fortran Oracle IDE "P

Oracle Oracle Solaris Studio IDE makefile C C++ Fortran makefile IDE Solaris Linux C/C++/Fortran Oracle IDE P Oracle Solaris Studio 12.3 IDE 2011 12 E26461-01 2 7 8 9 9 Oracle 10 12 14 21 26 27 29 31 32 33 Oracle Solaris Studio IDE makefile C C++ Fortran makefile IDE Solaris Linux C/C++/Fortran Oracle IDE "Project

More information

2013 C 1 # include <stdio.h> 2 int main ( void ) 3 { 4 int cases, a, b, i; 5 scanf ("%d", & cases ); 6 for (i = 0;i < cases ;i ++) 7 { 8 scanf ("%d %d

2013 C 1 # include <stdio.h> 2 int main ( void ) 3 { 4 int cases, a, b, i; 5 scanf (%d, & cases ); 6 for (i = 0;i < cases ;i ++) 7 { 8 scanf (%d %d 2013 18 ( ) 1. C pa.c, pb.c, 2. C++ pa.cpp, pb.cpp, Compilation Error cin scanf Time Limit Exceeded 1: A 5 B 5 C 5 D 5 E 5 F 5 1 2013 C 1 # include 2 int main ( void ) 3 { 4 int cases, a, b,

More information

Windows XP

Windows XP Windows XP What is Windows XP Windows is an Operating System An Operating System is the program that controls the hardware of your computer, and gives you an interface that allows you and other programs

More information

C C

C C C C 2017 3 8 1. 2. 3. 4. char 5. 2/101 C 1. 3/101 C C = 5 (F 32). 9 F C 4/101 C 1 // fal2cel.c: Convert Fah temperature to Cel temperature 2 #include 3 int main(void) 4 { 5 float fah, cel; 6 printf("please

More information

untitled

untitled 1 7 7.1 7.2 7.3 7.4 7.5 2 7.1 VFT virtual 7.1 3 1 1. 2. public protected public 3. VFT 4. this const volatile 4 2 5. ( ) ( ) 7.1 6. no-static virtual 7.2 7. inline 7.3 5 3 8. this this 9. ( ) ( ) delete

More information

提问袁小兵:

提问袁小兵: C++ 面 试 试 题 汇 总 柯 贤 富 管 理 软 件 需 求 分 析 篇 1. STL 类 模 板 标 准 库 中 容 器 和 算 法 这 部 分 一 般 称 为 标 准 模 板 库 2. 为 什 么 定 义 虚 的 析 构 函 数? 避 免 内 存 问 题, 当 你 可 能 通 过 基 类 指 针 删 除 派 生 类 对 象 时 必 须 保 证 基 类 析 构 函 数 为 虚 函 数 3.

More information

untitled

untitled MODBUS 1 MODBUS...1 1...4 1.1...4 1.2...4 1.3...4 1.4... 2...5 2.1...5 2.2...5 3...6 3.1 OPENSERIAL...6 3.2 CLOSESERIAL...8 3.3 RDMULTIBIT...8 3.4 RDMULTIWORD...9 3.5 WRTONEBIT...11 3.6 WRTONEWORD...12

More information

WWW PHP Comments Literals Identifiers Keywords Variables Constants Data Types Operators & Expressions 2

WWW PHP Comments Literals Identifiers Keywords Variables Constants Data Types Operators & Expressions 2 WWW PHP 2003 1 Comments Literals Identifiers Keywords Variables Constants Data Types Operators & Expressions 2 Comments PHP Shell Style: # C++ Style: // C Style: /* */ $value = $p * exp($r * $t); # $value

More information

extend

extend (object oriented) Encapsulation Inheritance Polymorphism Dynamic Binding (base class) (derived class) 1 class Base { int I; void X(); void Y(); class Derived: public Base { private: int j; void z(); Derived

More information

Scott Effective C++ C++ C++ Roger Orr OR/2 ISO C++ Effective Modern C++ C++ C++ Scoot 42 Bart Vandewoestyne C++ C++ Scott Effective Modern C++ Damien

Scott Effective C++ C++ C++ Roger Orr OR/2 ISO C++ Effective Modern C++ C++ C++ Scoot 42 Bart Vandewoestyne C++ C++ Scott Effective Modern C++ Damien Effective Modern C++ C++ C++ C++11/C++14 C++ Scott Meyers Gerhard Kreuzer Siemens AG Effective Modern C++ Effective Modern C++ Andrei Alexandrescu Facebook Modern C++ Design C++ C++ Nevin Liber DRW Trading

More information

Computer Architecture

Computer Architecture ECE 3120 Computer Systems Assembly Programming Manjeera Jeedigunta http://blogs.cae.tntech.edu/msjeedigun21 Email: msjeedigun21@tntech.edu Tel: 931-372-6181, Prescott Hall 120 Prev: Basic computer concepts

More information

Sun Storage Common Array Manager 阵列管理指南,版本 6.9.0

Sun Storage Common Array Manager  阵列管理指南,版本 6.9.0 Sun Storage Common Array Manager 阵 列 管 理 指 南, 版 本 6.9.0 文 件 号 码 :E27519-01 2012 年 2 月 版 权 所 有 2007, 2011, Oracle 和 / 或 其 附 属 公 司 保 留 所 有 权 利 本 软 件 和 相 关 文 档 是 根 据 许 可 证 协 议 提 供 的, 该 许 可 证 协 议 中 规 定 了 关

More information

PowerPoint 演示文稿

PowerPoint 演示文稿 Linux 操 作 系 统 基 础 介 绍 课 程 目 标 及 要 求 了 解 Linux 操 作 系 统 的 登 入 方 式 掌 握 常 用 命 令 的 基 本 用 法 能 够 熟 练 在 各 个 目 录 转 换 Outline 1. Linux 操 作 系 统 简 介 2. Linux 操 作 系 统 的 登 录 3. Linux 操 作 系 统 的 目 录 结 构 4. 常 用 命 令 5.

More information

bingdian001.com

bingdian001.com TSM12M TSM12 STM8L152C6, STM8L152R8 MSP430F5325 whym1987@126.com! /******************************************************************************* * : TSM12.c * : * : 2013/10/21 * : TSM12, STM8L f(sysclk)

More information