standards

Is there a standard pointer size declaration?

不羁的心 提交于 2019-12-01 20:21:53
I have struct with padding in char (oops, my bad). I would like to subtract a pointer size. Do you know a standard pointer size declaration, or a standard macro for that? sizeof (void *) Do you want the C-standard answer, or the answer that works pretty much all the time? Usually, all pointers to data are the same size, which is sizeof(void*) . But since you tagged "C" and "standards", note that this is not required by the C standard. I think it is required by POSIX, and is also true on Win32, and none of the common modern architectures have instructions involving different-sized pointers. One

how can I write an ANSI C console screen buffer?

僤鯓⒐⒋嵵緔 提交于 2019-12-01 19:56:52
I'm working on making an ASCII based game, and everywhere I look people are saying to use Console.Write() from MSDN, which is dandy and all if you're using Windows, but I'm not. And thus, I'm trying to write a function, or group of functions in C that can alternate between two screen buffers, and write them to the screen, similar to what man pages would be like, as well as pico, vim, and emacs. I have the buffer's working, and found an old ASCII game for linux called 0verkill that uses C and putchar() to place each character on the screen, but all of my attempts to re-create that, result in a

Which HTML version should be chosen for a public website

前提是你 提交于 2019-12-01 18:36:29
问题 I am currently working on a website. After studying HTML5 and its features I want to go ahead with it. I want to use features like offline storage, data- attribs, simple chat support etc. but because HTML5 is not well-supported yet, I am a bit confused. I have always used XHTML 1.0 transitional until now; should I continue using it or should I use HTML5? I have seen the web giants like google have completely shifted to HTML5. 回答1: HTML5 is a set of mostly-unrelated features. You can use

Should an empty base class affect the layout of the derived class?

会有一股神秘感。 提交于 2019-12-01 18:17:41
The C++ standard (quoting from draft n3242) says the following about subobjects [intro.object]: Unless an object is a bit-field or a base class subobject of zero size, the address of that object is the address of the first byte it occupies. Two distinct objects that are neither bit-fields nor base class subobjects of zero size shall have distinct addresses. Now, given the following snippet: struct empty { }; struct member: empty { }; struct derived: empty { member m; }; int main(void) { printf("%d", sizeof(derived)); return 0; } gcc I believe prints out 2 , and Visual C++ 2010 prints out 1 . I

Why does C++ list initialization also take regular constructors into account?

偶尔善良 提交于 2019-12-01 17:45:34
In C++ when using initializer_list syntax to initialize an object, the regular constructors of the object also participate in overload resolution, when no other list initialization rule applies. As far as I understand it, the following code calls X::X(int) class X { int a_; X(int a):a_(a) {} ); void foo() { X bar{3}; } But I don't understand, why regular constructors also are considered in context of initializer_lists. I feel that a lot of programmers now write X{3} to call a constructor instead of X(3) to call the construcor. I don't like this style at all, as it makes me think the object

JavaScript event handlers execution order

房东的猫 提交于 2019-12-01 17:30:51
Having this JS code: document.getElementById('e1').addEventListener('click', function(){alert('1');}, false); document.getElementById('e2').addEventListener('click', function(){alert('2');}, false); document.getElementById('e1').click(); document.getElementById('e2').click(); I'm wondering in what order will the alerts show up - will it be in the order the events were triggered by click() or could it be random? I'm asking about documented/standardised behaviour, not about what browsers currently implement. The alerts will be executed in order - 1 and then 2 . This is because click event is

Can enum member be the size of an array in ANSI-C?

与世无争的帅哥 提交于 2019-12-01 17:09:53
问题 I need to allocate an array according to how many elements the enum have. I did the following: enum { A, B, C, LAST }; char buf[LAST]; That works fine,even with -ansi -pedantic flags. But I'm not sure if it's a GCC or clang(wich supports most,if not all GCC-extensions) extensions or really allowed by the ANSI C standard and will works fine in any C compiler with ANSI-C std. Can someone clarify it? 回答1: Both the C89 (section 3.5.2.2) and C99 (section 6.7.2.2) standards define enums the same

SFINAE, deduction vs. instantiation

China☆狼群 提交于 2019-12-01 17:08:36
This code fails to compile in most compilers but at first I intuitively expected SFINAE to protect me: typedef void (*A)(); template < typename T > struct a_metafun { typedef typename T::type type; }; template < typename T > typename a_metafun<T>::type f(T) {} template < typename T> void f(T(*)()) {} int main() { f(A()); } I can fix the problem in at least two ways: 1) Change the definition of "metafun" f() to: template < typename T > typename T::type f(T) {} 2) define "a_metafun" such that it analyzes T and has a type if T has one and doesn't if it doesn't...but instantiates without error

Why String.prototype.substr() seems to be deprecated?

こ雲淡風輕ζ 提交于 2019-12-01 16:46:25
It is mentionned on the ECMAScript standard here that : ... These features are not considered part of the core ECMAScript language. Programmers should not use or assume the existence of these features and behaviours when writing new ECMAScript code. ECMAScript implementations are discouraged from implementing these features unless the implementation is part of a web browser or is required to run the same legacy ECMAScript code that web browsers encounter. There is also a red warning on MDN : String.prototype.substr() MDN doc Does anyone know why (ECMAScript standard say that) programmers

Why String.prototype.substr() seems to be deprecated?

天大地大妈咪最大 提交于 2019-12-01 16:45:00
问题 It is mentionned on the ECMAScript standard here that : ... These features are not considered part of the core ECMAScript language. Programmers should not use or assume the existence of these features and behaviours when writing new ECMAScript code. ECMAScript implementations are discouraged from implementing these features unless the implementation is part of a web browser or is required to run the same legacy ECMAScript code that web browsers encounter. There is also a red warning on MDN :