G*******s 发帖数: 4956 | 1 static的已经编译到可执行程序里了
还link什么呢?
除非看make文件? |
|
w*s 发帖数: 7227 | 2 【 以下文字转载自 Programming 讨论区 】
发信人: wds (网虫都是loser), 信区: Programming
标 题: pls recommend a good c++ math/statics lib (besides matlab)
发信站: BBS 未名空间站 (Wed Aug 14 05:04:23 2013, 美东)
in linux |
|
m***t 发帖数: 254 | 3 maybe this is a dumb question, but why static variable can not be put into
stack section? |
|
c*****z 发帖数: 182 | 4 我在编译的时候使用了-static选项
而且我的库文件都是*.a
但是我用 ldd executable_name
发现还是有很多动态库
我还能做些什么呢,谢谢! |
|
g*****g 发帖数: 34805 | 5 I guess the interviewer is talking about passing a static variable
into the function. |
|
|
c***d 发帖数: 996 | 7 ☆─────────────────────────────────────☆
goodbug (好虫) 于 (Thu Sep 14 23:51:01 2006) 提到:
In java, you use static initialization block, I am too dumb to
understand C++ now.
initiali
☆─────────────────────────────────────☆
crystalike (Newly Wed) 于 (Fri Sep 15 10:31:25 2006) 提到:
so singleton is an antipattern pattern. lol
☆─────────────────────────────────────☆
smectite (coolrant) 于 (Mon Sep 18 08:13:19 2006) 提到:
So what is ur point.
Firstly, I've never talked about any shippable types |
|
c***d 发帖数: 996 | 8 ☆─────────────────────────────────────☆
blueivan (bl.ue) 于 (Mon Nov 6 16:48:51 2006) 提到:
编译器到底是用值还是用变量???
☆─────────────────────────────────────☆
NeverLearn (Nice people finish last) 于 (Mon Nov 6 17:02:23 2006) 提到:
It has to be variable-oriented since you can type cast away the
constness of a variable, so you can NOT assume it never changes.
☆─────────────────────────────────────☆
Pontiff (需要一点运气--to candidacy) 于 (Mon Nov 6 17:51:11 2006) 提到:
variable. just as static storage s |
|
c**a 发帖数: 316 | 9 比如 如果operator new不是static的,
A* p = new A();
是那个 A的实体调用了 operator new 呢? |
|
s***e 发帖数: 122 | 10 不是很熟悉这种比较深的东西,不过我的理解是,非static的成员函数都事实上隐含了
第一个参数this,所以它的参数应该就跟应该重载的operator new不match了吧。 |
|
c**a 发帖数: 316 | 11 class A{
public:
void* operator new(size_t){A* p=this;};
}
编译器如是说,
d:\documents\visual studio 2005\projects\xx1\xxx1\xxx1.cpp(20
) : error C2671: 'A::operator new' : static member functions do not have
'this' pointers |
|
c**a 发帖数: 316 | 12 。。。
编译器不是说了嘛
编译器这么说就是暗示, operator new 必须是 static的, 您老忘记加了,我给免费
加上了
你想过thrust说的了吗? |
|
c****m 发帖数: 824 | 13 我有一个perl函数,想在里面申明一个static变量,每次call她的时候能像c++一样保
持上次得值。能做到么? |
|
b***y 发帖数: 2799 | 14 ☆─────────────────────────────────────☆
yapple (Fedora) 于 (Tue Jul 12 17:47:25 2005) 提到:
code is:
#include
using namespace std;
class B
{
public:
B()
{
cout << "construct a new B" << endl;
}
~B()
{
cout << "destruct a B object" << endl;
}
void print()
{
cout << "Hello, I am B!" << endl;
}
};
class A
{
public:
void func()
{
static B* pb;
if(!pb)
{
pb = new B();
} |
|
|
|
z***e 发帖数: 5393 | 17 有这种实现方法,但是前段时间好象这里有讨论过说其实这个靠local static的方式仍
然不可靠。 |
|
E*****7 发帖数: 128 | 18 WRONG: const data member of a class can be static!
(Comment: there are many misleading answers given by other persons in your original post.They are really misleading!) |
|
b***y 发帖数: 2799 | 19 如果定义了一个inline function, 并在多个程序文件里调用, 这个function里有stati
c variable, 如果这个funciton确实被inline了, 是不是会有多个static variable的c
opy? |
|
s******n 发帖数: 21 | 20 Interesting... Here is how the standard has to say :
"An inline function with external linkage shall have the same address in
all translation units. A static local variable in an extern inline function
always refers to the same object...."
The wording mentions "extern" specially, Is this international? If the
inline function is not declared extern, is the behavior undefined?
stati
的c |
|
t****t 发帖数: 6806 | 21 interesting indeed
i didn't notice the "extern inline" used here, I thought it should be
something like "external" inline, i.e. inline function with external linkage
, in other words, inline function not declared static or in unnamed
namespace
but who knows
just checked N2798, the wording is exactly the same
function |
|
X****r 发帖数: 3557 | 22 DEFINE_MUTEX是一个宏,定义在linux/include/linux/mutex.h
#define DEFINE_MUTEX(mutexname) \
struct mutex mutexname = __MUTEX_INITIALIZER(mutexname)
所以这里static是用来修饰一个变量dst_gc_mutex。
function? |
|
i*****f 发帖数: 578 | 23 【 以下文字转载自 Python 俱乐部 】
发信人: icewolf (好好活), 信区: Python
标 题: Static variables in function
发信站: BBS 未名空间站 (Fri Feb 12 16:50:57 2010, 美东)
# method 1: a callable instance
# pros: good encapsulation
# cons: too verbal
class _func_with_static_var:
def __init__(self):
self.static_var = 0
def __call__(self, *args):
self.static_var += 1
print self.static_var
func_with_static_var = _func_with_static_var()
# method 2: pass as a list with default value
# pros: less verbal
# cons: a |
|
d****p 发帖数: 685 | 24 There is nothing wrong as long as you use include guard against fruit.h
Multiple definitions of object with external linkage can be in different
translation units. And the static variable
has internal linkage.
So many cow guys miss this simple issues :-) |
|
d****p 发帖数: 685 | 25 You really confused me :-(
Header file A:
class Foo
{
..static int a;
};
int Foo::a = 0;
...
We can build N libraries L1, L2, ..., Ln each of which includes file A. And
all these libraries can be linked
together. Wrong? |
|
z****e 发帖数: 2024 | 26 static除了internal linkage以外还有一个概念,就是全局就一个啊。
然后就重复定义拉。
你说说。
has |
|
z****e 发帖数: 2024 | 27 唉,其实不仅仅是static,任何一个定义,除了inline,都不能重复的。
不信你自己写个member函数,重复定义一下就知道了啊。
哈哈哈哈。
面试官也水了啊。。。 |
|
t****t 发帖数: 6806 | 28 "全局就一个"是external linkage推出来的. internal linkage全局可以不止一个(因
为它根本就不出现在符号表里).
static用在class里不是internal linkage. |
|
z****e 发帖数: 2024 | 29 恩,师傅说得对,但是C里边const是默认 extern的,到了C++,才必须写extern,否则
就internal了。
是,inline 和 linkage是完全无关的,和vritual完全无关的,和static完全无关的,
但是我的意思是inline可以重复定义,这是我唯一知道的可以重复定义的东东。 |
|
t****t 发帖数: 6806 | 30 oh actually you are right, inline is not related to linkage.
but namespace scope static means internal linkage. |
|
t****t 发帖数: 6806 | 31 wait, that's a typo. i meant namespace scope static means internal linkage...
立。 |
|
s******e 发帖数: 431 | 32 << T2:第一个线程打印i,i的值应该是3,然后两个线程退出foo(),
应该打印5. 你可以想象static 相当于全局变量。 |
|
e****d 发帖数: 895 | 33 what kind of compiler do you use? static const char should be
able to define in class. |
|
g*********s 发帖数: 1782 | 34 yes i'm using g++ 4.4.3.
so "static const char orig_char = '@'" in the class definition is not a
definition but a declaration, according to 2nd floor's comments?
if so what is the definition and what is the declaration for variables?
isn't the one with the initializer a definition?
totally confused here. |
|
g*********s 发帖数: 1782 | 35 in addition, why static const integral type needs such a special
treatment? it is really challenging to remember all of these special
cases. |
|
e****d 发帖数: 895 | 36 My gcc 4.4.5 doesn't have any problem to define static const char variable
in class. |
|
e****d 发帖数: 895 | 37 You can always define static class data members outside the class.
This specifical case just gives you some convinience. |
|
t****t 发帖数: 6806 | 38 actually, most things in c++ are definitions (thus also declarations).
the several cases that are declarations ONLY are:
* extern, without initializer
* function w/o body
* class/struct forward declaration
* typedef
* using
* static data member inside a class (this is where are you confused) |
|
e****d 发帖数: 895 | 39 How about static data member of templates?
Isn't it defined during implicit/explicit instantiation?
Which compilation unit is responsible for it if
multiple compilation units are using it?
units |
|
b*****e 发帖数: 474 | 40 But, for integral types, you can put static definitions there.
I think that's why LZ asked about the exception. That's something
in addition to the one definition rule. |
|
g*********s 发帖数: 1782 | 41 actually no patience to go through those thick textbooks anymore, although
i agree refreshing the memory is always good. most of time cplusplus.com
is enough.
on the other hand, lz obviously has no idea about static data member in a
class. |
|
p*********9 发帖数: 277 | 42 c和c++中的static有什么区别阿?
谢谢. |
|
a****l 发帖数: 8211 | 43 no difference, for a c static in c++. |
|
t****t 发帖数: 6806 | 44 that macro (PTHREAD_....blahblah) is in the form of {....}. for c++98, you
can only use it in static objects. c++0x allow you to do it for auto objects.
with
with |
|
g*********s 发帖数: 1782 | 45 base and derived both have a virtual static method with the same
signature. looks ok ah. |
|
g*********s 发帖数: 1782 | 46 static_virtual.cpp:3: error: member ‘s’ cannot be declared both virtual
and static
but is this compiler dependent, or explicitly forbidden in standard? |
|
z****e 发帖数: 2024 | 47 static只是借用了class作为namespace而已。
本质上和一个静态绑定的全局函数没有任何区别,显然不能virtual啊。 |
|