C /C++ static member variablestatic 放在class 的member variable 之前,稱為靜態成員變數(static member variable),如下範例中的 c. ... <看更多>
Search
Search
C /C++ static member variablestatic 放在class 的member variable 之前,稱為靜態成員變數(static member variable),如下範例中的 c. ... <看更多>
#1. C語言中static的作用及C語言中使用靜態函式有何好處
關鍵字“static”,譯成中文就是“靜態的”,所以內部函式又稱靜態函式。但此處“static”的含義不是指儲存方式,而是指對函式的作用域僅侷限於本檔案。 使用 ...
在C 中,談到變數範圍(scope)涉及許多層次,可以談到很複雜,這邊先談談全域 ... 因此若在函式中宣告 static 變數,代表著就算函式執行完畢,變數也不會消失。例如:
C Static. 創建時間: January-22, 2021. 在C 語言中使用 static 變數在函式呼叫之間儲存變數值; 在C 語言中使用 static 關鍵字來宣告檔案範圍內的變數.
在C語言及由其衍生出的C++與Objective-C等程式語言中,「static」是用於控制變數的生命周期和連接方式(即其作用域,亦即可見性)的保留字。確切來說,正如C族語言中 ...
#5. C語言丨靜態關鍵字static的三種用法總結 - 有解無憂
不同于其他關鍵字,他們都有多種用法,而且在一定環境下使用,可以提高程式的運行性能,優化程式的結構,這篇文章主要介紹了C語言中靜態關鍵字static ...
#6. C/C++ 中的static, extern 的變數 - Medium
static 出現在variable 之前,且該variable 並不是宣告在某個function 中(C/C++); static 出現在class 的member variable 之前(C++ only); static 出現在class 的member ...
当我们同时编译多个文件时,所有未加static 前缀的全局变量和函数都具有全局可见性。为理解这句话,我举例来说明。我们要同时编译两个源文件,一个是a.c,另一个是main.c ...
IsNullOrEmpty() 是靜態方法static function。同樣的案例發身在C/C++、JAVA身上都有。筆者身邊有一些朋友一直搞不懂這是甚麼意思,本篇就此問題來做討論。
由於工作的關係使用的是C語言,而static的關鍵字我卻常以JAVA的角度來理解而造成誤解,經過trace大量的code和翻查一些書後,我總算搞懂static在C語言 ...
#10. C/C++中static的用法全域性變數與區域性變數 - 程式人生
1.什麼是static? static是C/C++中很常用的修飾符,它被用來控制變數的儲存方式和可見性。
#11. static 修飾詞- C# 參考
使用 static 修飾詞來宣告靜態成員,而靜態成員屬於類型本身,而不是特定物件。 static ... 從c # 8.0 開始,您可以將 static 修飾詞加入至區域函數。
#12. Static Variables in C - GeeksforGeeks
Static Variables in C ... Static variables have a property of preserving their value even after they are out of their scope! Hence, static ...
#13. c和c 中static const用法 - 程式前沿
c 語言中static的用法:1、全域性靜態變數: 用法:在全域性變數前加上關鍵字static,全域性變數就定義成一個全域性靜態變數。 static int temp; ...
#14. [C] Static variable/function - 過自己想過的生活- 痞客邦
從學C語言開始,至始至終都沒有弄懂variable 或function 前加個Static 的作用到底是甚麼,網路上找了一些資料,參考參考-- from: stackoverflow http.
#15. 【程式】C/C++的static保留字 - 創作大廳- 巴哈姆特
另一篇程式心得,從底層知識看static的用法。 C/C++把static保留字用在五個地方函式裡的stati.
#16. 【粉絲問答10】C語言關鍵字static的使用詳解 - IT人
BSS(Block Started by Symbol)通常是指用來存放程式中未初始化的全域性變數和靜態變數的一塊記憶體區域。 特點是:可讀寫的, ...
#17. [轉]static variable in C/C++ - 轉貼部落格- 痞客邦
面試工作時常常被問到這樣子的問題static變數/函式在C/C++的意義先從C說起倘若static出現在global function/variable的前頭代表著是這個function/
#18. C語言中static的用法!這裡是重點,要記 - 每日頭條
static int a:. 則變量a的作用域被縮小至本程序文件filel.c,文件file2.c中不能引用。 值得注意的是 ...
#19. 第二十七章| 函式入門- 變數、函式可視範圍(static 與extern)
C 語言教學,函式入門- 變數、函式可視範圍(static 與extern),全域變數(Global variable)、區域變數(Local variable)、區塊變數(Block variable)。
#20. static在C和C 中的用法和區別 - w3c菜鳥教程
static 主要有三個作用:. (1)區域性靜態變數. (2)外部靜態變數/函式. (3)靜態資料成員/成員函式. 前兩種c和c++都有,第三種僅在c++中有,下面分別作 ...
#21. Static (Function) - Welkin小窩- 痞客邦
有一些C 的語法,在C++ 的程序員相對少用。 但就是因為這個原因,有時就會忽略了。 假設我們有一個Header檔Foo.h: 有一些C 的語法,在C++ 的程序員 ...
#22. C/C++ static member variable 用法與初始化方式 - ShengYu Talk
C /C++ static member variablestatic 放在class 的member variable 之前,稱為靜態成員變數(static member variable),如下範例中的 c.
#23. Objective-C 快速導覽- static 變數 - 程式語言教學誌
Objective-C 快速導覽- static 變數. 類別(class) 中方法(method) 所定義的變數(variable) 都是區域變數(local variable) ,這是說離開方法後變數便不能保存其值,若是 ...
#24. [C/C++] 靜態函式(static function) | 逍遙文工作室
一些程式語言的語法很少使用,不過卻會在某些人寫的code上看到,讓我很想要搞懂它!靜態函式(static fu…
#25. c語言中static說明是什麼意思? - 劇多
是不止一個意思,要看用到哪裡。比如: static int a; int b; void func(void) { static int c; int d; } 在這裡,a與b都是全域性變數,二者的區別是,b ...
#26. Static in C - javatpoint
Static is a keyword used in C programming language. It can be used with both variables and functions, i.e., we can declare a static variable and static function ...
#27. static变量及其作用,C语言static变量详解
在C 语言中,static 关键字不仅可以用来修饰变量,还可以用来修饰函数。在使用static 关键字修饰变量时,我们称此变量为静态变量。 静态变量的存储方式与全局变量一样 ...
#28. 變數可視範圍以及是否常駐(Variable Scope & Static)
如果一個原始程式檔案,xxx.c 需要用到某一個廣域變數,這個廣域變數是來自於另一個檔案的定義,則我們必須用extern的關鍵字,告訴編譯器,這個變數是 ...
#29. What does "static" mean in C? - Stack Overflow
In the C programming language, static is used with global variables and functions to set their scope to the containing file.
#30. C++ 的static-靜態變數與函式詳細說明 - 伊卡洛斯之翼
C++ 的static-靜態變數與函式詳細說明. 此篇文章已移至以下網址 https://husking-studio.com/cpp-static/. 文章標籤. C++ static 靜態. 全站熱搜 ...
#31. [C觀念] static 定義變數觀念 - 不會的就放這邊
include int i; int main(void){ for (i=0;i<10;i++){ static int gg=0; printf("%d\n.
#32. The static keyword in C - C Programming
The static keyword in C is a storage-class specifier. It has different meanings, depending on the context. Inside a function it makes the variable to retain ...
#33. 幹嘛static inline?
main.c */ inline void foo(); int main() { foo(); return 0; }. 因為 foo() 沒有 static ,main.c是可以宣告並使用foo.c的 foo() 的,而且可以獨立編譯main.c和foo.c ...
#34. [轉]C語言的static用法 - 博客园
1. 使用在全域變數或全域函式(Global variable &Global function)讓該變數(或該函式)的可視範圍只侷限在該檔案內,其他的.c檔看不到此變數(或函式)的 ...
#35. C陷阱: extern & static & 多檔案、宣告、定義、變數
C 陷阱: extern & static & 多檔案、宣告、定義、變數、函式 ... file.c int main( void ) { var++; // compiler 未分配 var 空間 return 0; } ...
#36. c語言關鍵字static - 程序員學院
c 語言關鍵字static,來自static作用修飾函式區域性變數全域性變數在c語言中,static的字面意思很容易把我們匯入歧途,其實它的作用有三條。 1.
#37. static members - cppreference.com
static members. From cppreference.com. < cpp | language · C++ ... Inside a class definition, the keyword static declares members that are ...
#38. C中的靜態變量
如何在C中使用靜態變量. 在函數內部,您可以初始化一個靜態變量使用 static 關鍵詞。 ... int incrementAge() { static int age = 0; age++; return age; }.
#39. Static - Learn C - Free Interactive C Tutorial
What is a static variable? ... By default, variables are local to the scope in which they are defined. Variables can be declared as static to increase their scope ...
#40. 在c中static和const的區別 - 嘟油儂
1樓:非典型天秤座. static為靜態修飾符,可以放在物件. 前面(函式也是一種物件)如:. class example. }可直接example.show();去呼叫這個方法而不用 ...
#41. 107.08.25 C 語言static 和shared 函式庫 - 記錄用
$ gcc -c main.c $ gcc -c -fPIC adder.c $ gcc -o adder.dll -shared adder.o $ gcc -o main main.o -L. -ladder -Wl,-rpath=. 4. Ubuntu - static (.a)
#42. c语言中static关键字用法详解_guotianqing的博客
概述static关键字在c语言中比较常用,使用恰当能够大大提高程序的模块化特性,有利于扩展和维护。但是对于c语言初学者,static由于使用灵活, ...
#43. Internal and External Linkage in C - wdv4758h-notes latest ...
副標題: extern/static/inline variable/function. Table of Contents. Internal and External Linkage in C. compiling, linking and forward declaration ...
#44. Linux中的Static @ 十年磨一劍 - 痞客邦
static 在c 當中的用法有下列幾種:. 1. function 內的變數使用static 宣告. 如:. void MyFun(). {. static int i=0;. } i 為static,i 的生命週期會 ...
#45. VESSEL® Static electricity removal A C Pulse, Clean bar C-90 ...
Product categories:Air static eliminatorPower supply (V):DC24 ± 5% [connector RJ45]Air pressure used (MPa):0.3.
#46. The static keyword in C++ | 打字猴
在C++中,static有很多不同的意思,打字猴也常遇到static相關的問題(多半是名詞解釋),所以在這篇文章中做一個整理:. 1. static修飾local variables
#47. static在C和C++中的用法和区别 - 腾讯云
在C中static有了第二种含义:用来表示不能被其它文件访问的全局变量和函数。但为了限制全局变量/函数的作用域, 函数或变量前加static使得函数成为静态 ...
#48. 【c語言】關鍵字存儲類型講解(auto,extern,static,register,const)
C 的存儲類別有4種:自動的(auto)、靜態的(static)、寄存器的(register)、外部的(extern)。變量的存儲類別對應變量的作用域與生命週期。 1.extern.
#49. Static functions in C - Tutorialspoint
A static function in C is a function that has a scope that is limited to its object file. This means that the static function is only ...
#50. C 語言程式的記憶體配置概念教學 - GT Wang
本篇介紹C 語言程式的記憶體配置概念,並以實際的範例程式碼來說明。 ... 有經過初始化的C 語言的全域變數(global variables)以及靜態變數(static ...
#51. Helix QAC for C and C++ | Perforce
Helix QAC is a static code analysis tool for C and C++. It has been the preferred static code analyzer in tightly regulated and safety-critical industries ...
#52. 程式開發| C/C++ static 關鍵字用途 - NoSleep | 資訊癮想力
A static variable inside a function keeps its value between invocations. A static global variable or a function is "seen" only in the file it's ...
#53. [C#] static筆記| UG部落 - 點部落
一直以來對static不是很清楚, 所以順手來做個筆記. ... [C#] static筆記 ... static class CompanyInfo { public static string GetCompanyName() ...
#54. static link & Dynamic Link & Load - 日常瑣碎事- 痞客邦
static link & Dynamic Link & Load · Compile source codes # gcc -c file1.c file2.c file3.c · Create a shared library named libmylib.so
#55. Using the static keyword in C - Embedded blog - Arm ...
Static variables declared at the module level are initialized only once during the C copy down that occurs when the processor is being ...
#56. C语言丨static 函数和普通函数的区别 - BiliBili
1、全局变量在全局变量之前加上关键字static,全局变量就被定义成为一个全局静态变量,则有: 1)内存中的位置:静态存储区(静态存储区在整个程序 ...
#57. A standardised static in vitro digestion method suitable for food
Simulated gastro-intestinal digestion is widely employed in many fields of food and nutritional sciences, as conducting human trials are often costly, ...
#58. static變數及其作用,C語言static變數詳解 - tw511教學網
在C 語言中,static 關鍵字不僅可以用來修飾變數,還可以用來修飾函數。 ... 但並不是靜態變數,它必須由static 加以定義後才能成為靜態全域性變數。
#59. static function or static member 用途整合整理 - CHG
一樣可用在計數總共被創建幾次。 設定方式比較特別宣告後只能在類別外初始化. class OBJ{ static int c; }; int OBJ::c = 0; ...
#60. C语言关键字static 的用法 - 知乎专栏
C 语言static 关键字的常见用法有三种: 用于局部变量的修饰符;用于全局变量的修饰符;用于函数的修饰符。1、用于局部变量的修饰符当static 用于修饰 ...
#61. Component Testing C: How to test a static variable of a function
Your C code under test contains a static variable. How do you access the variable within the IBM® Rational® Test RealTime™ test script?
#62. c語言中static修飾函數的方法及代碼 - WalkonNet
3、使用static聲明的函數不能被另一個文件引用。 實例. /* file1.c */ #include <stdio.h> static void fun(void) { printf("hello from fun.
#63. C语言中static变量详解 - 简书
转:https://www.cnblogs.com/getyoulove/p/3656184.html Static翻译出来是“静态”“静止”的意思,在C语言中的意思其实和它...
#64. [C語言]靜態的迷思-static@約書亞程式集|PChome 個人新聞台
在C 裡面常常看到static 這個keyword, 用在變數或函式之前不一, 既然用了呢, 就表示它的使用與否會有不一樣的意思. 區域變數 一般的區域變數是在每次 ...
#65. static(计算机高级语言关键字)_百度百科
像在VB,C#,C,C++,Java,PHP,Objective-C,JavaScript中我们可以看到static作为关键字和函数出现,在其他的高级计算机语言 ...
#66. Library可分成三種,static、shared與dynamically loaded ...
Static librariesStatic 程式庫用於靜態連結,簡單講是把一堆object檔用ar(archiver)包裝集合 ... ____ hello.c ____#include void hello(){ printf(”Hello @ @ tzeng015.
#67. Static variables in C - Flavio Copes
How to work with static variables in C. ... Inside a function, you can initialize a static variable using the static keyword.
#68. IAR C-STAT - Static analysis tool - STMicroelectronics
IAR C-STAT - Static analysis tool; add-on product to IAR Embedded Workbench, PP-IAR-CSTAT, STMicroelectronics.
#69. How To Implement Static Variable In C | Edureka
Static Variable In C · Data segments are used to allocate a static variable and not stack segments. · Static variables by default have some values ...
#70. The C keyword 'static' - Embedded.com
In C and C++, the keyword 'static' has two, quite separate uses. In C++, there is even a third use of the keyword. The nuances of these ...
#71. C# - const vs static readonly | John Wu's Blog
偶而遇到有人問const 跟static readonly 有什麼差別,如果是使用基本型別或字串,可能會感覺差不多。大部分的人都會回答是賦予值的階段不同,const 是 ...
#72. IDEA Section 618 Data Products: Static Tables - US ...
Part C Child Count and Settings. #, Title, File by Years. 1. Number of infants and toddlers ages birth through 2 and 3 and older ...
#73. [C] static 與extern - 29
[C] static 與extern. static變數,當變數有宣告時加上static限定時,一但變數生成,它就會一直存在記憶體之中,即使函式執行完畢,變數也不會消失, ...
#74. All you need to know about C Static libraries - DEV Community
To create a static library, we need to specify to the compiler, which is GCC in our case, that we want to compile all library codes (*.c) into ...
#75. Static Function Usage in C | Toolbox Tech
Yes. You can use static function in C. static int funcABC(void) ;. The scope of this function is limited to the file in which you define it.
#76. cppcheck : An Open Source C/C++ Static Code Analysis Tool
先解釋一什麼叫Static Code Analysis(簡稱SCT好了),顧名思義:不會動的時候分析一下code。也可以看到wikipedia的條目這通常由自動化的工具來分析(不然,我想C...
#77. Learn About Static Variable in C [With Coding Example]
Static Keyword in C is a programming concept. While a general variable limits its scope, the scope of the static variable extends throughout ...
#78. C++ static關鍵字 - 億聚網
下面來看看看C++中靜態( static )字段的簡單示例。 #include <iostream> using namespace std ...
#79. C++ library support - NDK - Android Developers
No headers, limited C++. libc++ is available as both a static and shared library. Warning: Using static runtimes can cause unexpected behavior.
#80. C static code analysis: "memset" should not be used to delete ...
C static code analysis. Unique rules to find Bugs, Vulnerabilities, Security Hotspots, and Code Smells in your C code. All rules 309 · Vulnerability13 ...
#81. Static Code Analysis Tools - PVS-Studio
Clang Static Analyzer. Static code analyzer for C/C++/Objective-C languages built into the Clang compiler. However, many other compilers ...
#82. C++ 類別class static - 程式語言教學- 痞客邦
< C++完整教學目錄>. 若在建立類別時,欲讓所有該類別物件都「共享」一個變數(意思是說,這個變數在所有該類別物件裡的值都一樣,若經更改,則此變數 ...
#83. How Static Keyword works in C? with Examples - eduCBA
Static keyword in C varies differently in a way that it is a keyword that can be used with variables as well as with functions. Therefore, it is very much ...
#84. Cppcheck - A tool for static C/C++ code analysis
Cppcheck is an analysis tool for C/C++ code. It detects the types of bugs that the compilers normally fail to detect. The goal is no false positives.
#85. C++ 變數的存放位置跟static三個用法 - 東方和風語
static int c; void main(){ } 在編譯程可執行檔的時候,會將所需程式或lib變成目標檔(.o)再透過連結器(linker)將他們link起來,才會變成我平常所需的 ...
#86. Python中可以使用靜態類變量嗎? (Are static class variables ...
這與C ++和Java不同,但與C#並沒有太大區別,在C#中,無法使用對實例的引用來訪問靜態成員。 看到Python教程對類和類對象的看法。 @Steve Johnson已經回答有關靜態方法,也記錄 ...
#87. C/C++ 及Java 中static 的含义总结
static 关键字在C/C++ 及Java 语言中都有其特定的含义,本文做一简单总结。 static in C. 1. static 全局变量. static 全局变量和其它全局变量都是 ...
#88. SLMT's Tutorial Blog: 小山的C# 教學-第19課-static 修飾字
重點提示 1. 使用了static 修飾過的變數、method,不需要建立物件就可以直接透過class 名稱使用 2. static 修飾過的變數是所有同class 的物件共用的
#89. 有關C語言的static用法 - prague12 - 痞客邦
參考: http://archerworks.blogspot.com/2010/07/cstatic.html 有關C語言的static用法 1. 使用在全域變數或全域函式(Global variable & Global function)
#90. c++中static用法笔记
static 的作用主要有两种: 第一个作用是限定作用域;第二个作用是保持变量内容持久化; c语言中static的用法: 1、全局静态变量: 用法:在全局变量前 ...
#91. C++ 資料成員初始化@ C++11/17(inline variable)
不過,在C++11 的時候,C++ 標準終於支援non-static data member initializer 了! 所以如果只是要初始化資料成員,就可以簡單寫成:.
#92. Top 9 C++ Static Code Analysis Tools - Incredibuild
When talking about C++, DevOps, DevSecOps, Agile, speed, and the shift left approach (there's a lot of talking), it seems that the landscape ...
#93. 標籤彙整: static library - C瓜農場
網路上找得到一些編譯成DLL的, 但這邊要做的是static library, 也就是將openssl包進exe中不 ... perl Configure VC-WIN32 no-asm –prefix=c:/openssl/
#94. C-STAT | IAR Systems
Static analysis of C and C++ code. Static analysis helps you to find potential issues in your code by doing an analysis on the source code level.
#95. Atmel Studio: Creating and linking GCC C Static Library Project
This article provides steps for creating and linking a new GCC C Static library in Atmel Studio IDE.
#96. [問題] 請問static是什麼意思... - 精華區C_and_CPP - 批踢踢 ...
在C/C++ 中,static 修飾詞在不同地方的意義不同。我看你附上的程式碼只有看到加在local variable 之前的,那樣的寫法稱作static local variable。
#97. C語言static用法小結
C 語言static用法小結static關鍵字是C, C++中都存在的關鍵字, 它主要有三種使用方式, 其中前兩種只指在C語言中使用, 第三種在C++中使用(C,C++中具體 ...
c - static 在 [問題] 請問static是什麼意思... - 精華區C_and_CPP - 批踢踢 ... 的推薦與評價
我又來問問題了-.-
近來在看個計算材料的code :
https://staff.aist.go.jp/t-ozaki/b-bop/b-bop.html
裡面用了一堆 static這修飾
看了一堆書 也問了人 還是搞不清處static到底是什麼意思啊..
又static在科學計算上有什麼好處 以至於這作者要大量使用...
fortran確定是沒有對應這語法的 =.=
煩請高手回答 謝謝!!!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 210.208.54.44
> -------------------------------------------------------------------------- <
作者: freesamael (燒賣) 看板: C_and_CPP
標題: Re: [問題] 請問static是什麼意思...
時間: Fri Oct 5 02:41:23 2007
※ 引述《OpenMX (材料探索者)》之銘言:
: 我又來問問題了-.-
: 近來在看個計算材料的code :
: https://staff.aist.go.jp/t-ozaki/b-bop/b-bop.html
: 裡面用了一堆 static這修飾
: 看了一堆書 也問了人 還是搞不清處static到底是什麼意思啊..
: 又static在科學計算上有什麼好處 以至於這作者要大量使用...
: fortran確定是沒有對應這語法的 =.=
: 煩請高手回答 謝謝!!!
在 C/C++ 中,static 修飾詞在不同地方的意義不同。我看你附上的程式碼只有看到
加在 local variable 之前的,那樣的寫法稱作 static local variable。
如果你對 c 語言的 scope 有點基礎概念,應該知道 local variable 只在 { } 區間
內有效,過了就消失。也就是說,它的壽命就只有在進入區間內到離開區間前。
一個區間可能是一個 function,或是 if、for、while,甚至是你在 function 內任何
地方隨便寫一組 { } 括弧也會成為一個區間。
Static local variable 的壽命跟 global variable 一樣長,但是只在宣告的 { }
區間內是可視的。也就是只有在 { } 區間內可以存取,但是其值在離開區間後仍會
保留,且初始化行為只會有一次。
以下例來說,function 被執行幾次,count 就會是多少。
void function()
{
static count = 0; // count 只有第一次會初始化成 0
count++;
}
你可能需要一本 c 語言的書籍當作輔助工具,不然類似的問題還會遇到很多。
--
Licensed under CC2.5(TW) by-sa, Samael Wang.
https://creativecommons.org/licenses/by-sa/2.5/tw/
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.135.82.153
> -------------------------------------------------------------------------- <
作者: mystea (mystea) 看板: C_and_CPP
標題: Re: [問題] 請問static是什麼意思...
時間: Fri Oct 5 15:44:02 2007
電腦的記憶體在執行程式時, 會被分成三區: permanent, stack 和 heap.
permanent區的變數會一直活到程式執行完, stack區的變數則是在{}執行完就被移除.
C的default是把global variable都放到permanent, local variable都放到stack.
但是有時候, 你希望local variable不要那麼短命...這時候加一個修飾詞static,
local variable就會被放到permanent variable裡了.
default會這樣定不是全然沒有道理的. global variable既然是大家都看得到的變數,
活到程式結束是天經地義. 而local variable既然在{}外的程式都看不到他, 很自然的選
則就是在離開{}後就把他清掉, 好節省記憶體. 只是在一些非常時期, 我們不希望{}外的
程式去碰那個變數, 卻又希望他能夠用來保存有用的資訊, 這個時候就要加上static了.
※ 引述《freesamael (燒賣)》之銘言:
: ※ 引述《OpenMX (材料探索者)》之銘言:
: : 我又來問問題了-.-
: : 近來在看個計算材料的code :
: : https://staff.aist.go.jp/t-ozaki/b-bop/b-bop.html
: : 裡面用了一堆 static這修飾
: : 看了一堆書 也問了人 還是搞不清處static到底是什麼意思啊..
: : 又static在科學計算上有什麼好處 以至於這作者要大量使用...
: : fortran確定是沒有對應這語法的 =.=
: : 煩請高手回答 謝謝!!!
: 在 C/C++ 中,static 修飾詞在不同地方的意義不同。我看你附上的程式碼只有看到
: 加在 local variable 之前的,那樣的寫法稱作 static local variable。
: 如果你對 c 語言的 scope 有點基礎概念,應該知道 local variable 只在 { } 區間
: 內有效,過了就消失。也就是說,它的壽命就只有在進入區間內到離開區間前。
: 一個區間可能是一個 function,或是 if、for、while,甚至是你在 function 內任何
: 地方隨便寫一組 { } 括弧也會成為一個區間。
: Static local variable 的壽命跟 global variable 一樣長,但是只在宣告的 { }
: 區間內是可視的。也就是只有在 { } 區間內可以存取,但是其值在離開區間後仍會
: 保留,且初始化行為只會有一次。
: 以下例來說,function 被執行幾次,count 就會是多少。
: void function()
: {
: static count = 0; // count 只有第一次會初始化成 0
: count++;
: }
: 你可能需要一本 c 語言的書籍當作輔助工具,不然類似的問題還會遇到很多。
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 76.170.235.113
> -------------------------------------------------------------------------- <
作者: meltice (三億兩千萬大散戶) 看板: C_and_CPP
標題: Re: [問題] 請問static是什麼意思...
時間: Sat Oct 6 11:19:28 2007
in C/C++
static variable就像是global變數
差別只在它的visible範圍只在該scope內
所以static變數的初始值就是0
當然你也可以像global變數一樣指定初始值給它
static function表示該function的visible範圍只在該.cpp內
可以避免污染global namespace
所以很多個.cpp內可以有同樣名稱的static function
在C++ class之中
static member variable在該class中始終只存在一份
不會因為new delete而有數量上的變化
需要在global定義初始值
不用宣告實體object即可存取該值
static member function
只允許存取static member variable或function
不用宣告實體object即可呼叫該function
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 60.245.93.33
... <看更多>