standards-compliance

How do I provide a default implementation for an Objective-C protocol?

笑着哭i 提交于 2021-02-05 20:21:44
问题 I'd like to specify an Objective-C protocol with an optional routine. When the routine is not implemented by a class conforming to the protocol I'd like to use a default implementation in its place. Is there a place in the protocol itself where I can define this default implementation? If not, what is the best practice to reduce copying and pasting this default implementation all over the place? 回答1: Objective-C protocols have no affordance for default implementations. They are purely

C++ new int[0] — will it allocate memory?

。_饼干妹妹 提交于 2020-03-18 08:53:59
问题 A simple test app: cout << new int[0] << endl; outputs: 0x876c0b8 So it looks like it works. What does the standard say about this? Is it always legal to "allocate" empty block of memory? 回答1: From 5.3.4/7 When the value of the expression in a direct-new-declarator is zero, the allocation function is called to allocate an array with no elements. From 3.7.3.1/2 The effect of dereferencing a pointer returned as a request for zero size is undefined. Also Even if the size of the space requested

How to allow certain ports open to world only for certain security groups in Cloud Custodian?

為{幸葍}努か 提交于 2020-01-25 10:02:08
问题 I have this in my policy to allow only 80 and 443 open to world. "or": [ { "Cidr": { "value": "0.0.0.0/0" }, "type": "ingress", "OnlyPorts": [ 80, 443 ] }, { "CidrV6": { "value": "::/0" }, "type": "ingress", "OnlyPorts": [ 80, 443 ] } ] Now, I want to allow only 8080 and 8081 to selected security groups, not for all security groups. Is this possible? 回答1: You need to edit particular security groups only. Just open the ports there and that will do it. 回答2: Add a value filter using a key and

Aliasing in Fortran function

非 Y 不嫁゛ 提交于 2020-01-15 03:32:10
问题 For optimisation reasons, Fortran enforces that the dummy arguments of a subroutine or function are not alias, i.e., they do not point the the same memory place. I am wondering if the same constraint applies to the returned value of a function. In other words, for a given myfunc function: function myfunc(a) real, intent(in) :: a(:) real :: myfunc(size(a)) myfunc = a * 2 end function myfunc is it standard-compliant to write: a = myfunc(a) and b = myfunc(a) ? 回答1: The arguments of a function

Does (size_t)((char *)0) ever not evaluate to 0?

*爱你&永不变心* 提交于 2020-01-11 05:21:27
问题 According to the responses in "Why subtract null pointer in offsetof()?" (and my reading of K&R), the C standard doesn't require that (size_t)((char *)0) == 0 . Still, I've never seen a situation where casting a null pointer to an integer type evaluates to anything else. If there is a compiler or scenario where (size_t)((char *)0) != 0 , what is it? 回答1: Well, as you know, the physical representation of null pointer of a given type is not necessarily all-zero bit pattern. When you forcefully

C++ how safe are self registering classes?

强颜欢笑 提交于 2020-01-01 10:12:19
问题 Coming from this thread I implemented a similar system in c++ to the chosen solution there. My problem now is that it is stated there by the user Daniel James that this solution might not work with every compiler (I'm using gcc currently) and is not defined in the c++ standard. Suppose I have an abstract base-class for the interface and a factory-class as a singleton that stores pointers to a function that constructs the specific classes derived from that interface. then I have a helper class

Is it undefined behavior to exceed translation limits and are there checker tools to find it?

不羁的心 提交于 2020-01-01 04:35:06
问题 ORIGINAL QUESTION: I'm searching the C90 standard for things to be aware of, when writing hignly portable code, while having low trust in the good will of the compiler vendor, and assuming that my software might kill somebody sometimes, if I do things wrong. Let's say I'm a little paranoid. At the moment I am thinking about the "Translation limits" (5.2.4.1 ANSI/ISO 9899:1990). As pointed out in the standard and in: "Does ansi C place a limit on the number of external variables in a program?"

c++ array zero-initialization: Is this a bug, or is this correct?

倖福魔咒の 提交于 2020-01-01 04:27:08
问题 Note: We are speaking about (supposedly) C++98 compliant compilers, here. This is not a C++11 question. We have a strange behavior in one of our compilers and we're not sure if this is Ok or if this is a compiler bug: // This struct has a default constructor struct AAA { AAA() : value(0) {} int value ; } ; // This struct has a member of type AAA and an array of int, both surrounded // by ints struct BBB { int m_a ; AAA m_b ; int m_c ; int m_d[42] ; } ; When BBB is initialized as such: BBB bbb

Can a destructor be recursive?

橙三吉。 提交于 2019-12-31 08:54:16
问题 Is this program well-defined, and if not, why exactly? #include <iostream> #include <new> struct X { int cnt; X (int i) : cnt(i) {} ~X() { std::cout << "destructor called, cnt=" << cnt << std::endl; if ( cnt-- > 0 ) this->X::~X(); // explicit recursive call to dtor } }; int main() { char* buf = new char[sizeof(X)]; X* p = new(buf) X(7); p->X::~X(); // explicit call to dtor delete[] buf; } My reasoning: although invoking a destructor twice is undefined behavior, per 12.4/14, what it says

Can a destructor be recursive?

旧时模样 提交于 2019-12-31 08:53:47
问题 Is this program well-defined, and if not, why exactly? #include <iostream> #include <new> struct X { int cnt; X (int i) : cnt(i) {} ~X() { std::cout << "destructor called, cnt=" << cnt << std::endl; if ( cnt-- > 0 ) this->X::~X(); // explicit recursive call to dtor } }; int main() { char* buf = new char[sizeof(X)]; X* p = new(buf) X(7); p->X::~X(); // explicit call to dtor delete[] buf; } My reasoning: although invoking a destructor twice is undefined behavior, per 12.4/14, what it says