> [3.6.2] > It is implementation-defined whether the dynamic initialization > ...(略)... is done before the first statement of main or deferred to > any point in time after the first statement of main but before the > first use of a function or object defined in the same translation unit.
>>590 freestanding まで視野に入れて議論するのは無意味だろ。そもそも組み込み系 だと「終了してはいけない = main から return した瞬間にハングアップ」とか「エン トリポイントが main じゃない」とかもアリアリだから。
hosted environment では C99 でも main は int のみ。以下、規格書から抜粋。
> 5.1.2.2.1 Program startup > 1 The function called at program startup is named main. The implementation declares no > prototype for this function. It shall be defined with a return type of int and with no > parameters: > > int main(void) { /* ... */ } > > or with two parameters (referred to here as argc and argv, though any names may be > used, as they are local to the function in which they are declared): > > int main(int argc, char *argv[]) { /* ... */ } > > or equivalent; or in some other implementation-defined manner.
>>630 C++標準ならできるが、Visual C++ならできない。 この場合はインナークラスで代用することはできる。はず(笑) template<class A, class B> class C { template <typename T> class sub { public: B func(T a) { ... } ...; }; template<> class sub<int> { public: B func(int a) { ... } ...; }; sub<A> impl; public: B func(A a) { return impl.func(a); } };
ANSI C++ の規格書から抜粋。 > 12.1 Constructors > 1 Constructors do not have names. ... > 2 ... Because constructors do not have names, they are never found during name lookup; ...