standards

Is conversion int -> unsigned long long defined by the standard

我怕爱的太早我们不能终老 提交于 2019-12-01 06:29:22
I can't find the exact specification of how int value is converted to unsigned long long in the standard. Various similar conversions, such as int -> unsigned, unsigned -> int (UB if negative), unsigned long long -> int, etc. are specified For example GCC, -1 is converted to 0xffffffffffffffff , not to 0x00000000ffffffff . Can I rely on this behavior? Yes, this is well defined, it is basically adding max unsigned long long + 1 to -1 which will always be max unsigned long long . This is covered in the draft C++ standard section 4.7 Integral conversions which says: If the destination type is

Portable way to achieve ls' -v flag (i.e. sort by version)?

泪湿孤枕 提交于 2019-12-01 06:24:42
I'm working on a some build scripts that I'd like to depend on only standardized features. I need to sort some files by version. Say the files are bar-1.{0,2,3} bar-11.{0,2,3}. By default, ls gives me: bar-1_0 bar-11_0 bar-11_2 bar-11_3 bar-1_2 bar-1_3 Getting what I want is easy using 'ls -v': bar-1_0 bar-1_2 bar-1_3 bar-11_0 bar-11_2 bar-11_3 The problem is that 'ls -v' is not standard . Standard sort also seems to lack the option I want, though I could be looking at old versions of the specs. Can anyone suggest a portable way to achieve this effect short of writing my own sort routine?

Why is it bad to type void main() in C++ [duplicate]

醉酒当歌 提交于 2019-12-01 06:22:33
Possible Duplicate: Difference between void main and int main? Why is void main() { //return void } bad? The other day I typed this and someone pointed out to me that it is wrong to do so. I was so confused. I have been writing like this for a while now, I know it isn't C++ standard, but the compiler doesn't give out any warnings. Why is this wrong? Because the compiler you use does not error out on it, it doesn't mean other compilers won't. You know its not standard, after all... Because every program should indicate to other programs whether or not it completed successfully, or if there was

Is RVO (Return Value Optimization) on unnamed objects a universally guaranteed behavior?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 06:07:10
This question is in different aspect (also limited to gcc). My question is meant only for unnamed objects . Return Value Optimization is allowed to change the observable behavior of the resulting program. This seems to be mentioned in standard also. However, this "allowed to" term is confusing. Does it mean that RVO is guaranteed to happen on every compiler. Due to RVO below code changes it's observable behavior: #include<iostream> int global = 0; struct A { A(int *p) {} A(const A &obj) { ++ global; } }; A foo () { return A(0); } // <--- RVO happens int main () { A obj = foo(); std::cout<<

Anonymous Methods / Lambda's (Coding Standards)

烈酒焚心 提交于 2019-12-01 05:29:14
问题 In Jeffrey Richter's "CLR via C#" (the .net 2.0 edtion page, 353) he says that as a self-discipline, he never makes anonymous functions longer than 3 lines of code in length. He cites mostly readability / understandability as his reasons. This suites me fine, because I already had a self-discipline of using no more than 5 lines for an anonymous method. But how does that "coding standard" advice stack against lambda's? At face value, I'd treat them the same - keeping a lambda equally as short.

Can I seek a position beyond 2GB in C using the standard library?

拜拜、爱过 提交于 2019-12-01 05:14:30
I am making a program that reads disk images in C. I am trying to make something portable, so I do not want to use too many OS-specific libraries. I am aware there are many disk images that are very large files but I am unsure how to support these files. I have read up on fseek and it seems to use a long int which is not guaranteed to support values over 2 31 -1. fsetpos seems to support a larger value with fpos_t but an absolute position cannot be specified. I have also though about using several relative seeks with fseek but am unsure if this is portable. How can I support portably support

Customize C# Standard Document Generators (XML Comments) in Visual Studio

匆匆过客 提交于 2019-12-01 04:32:09
问题 Is there any other kind of documentation generator shortcuts for C# (like /// Generates function() Code) or any tool item (like signature in email @ outlook) in VS IDE, For following MS Standard Coding & Documentation & making understand to other co-developer working on same project. How to change the Format of the Generated document in visual stdio IDE by default comment format to custom comment format shown below. Ex: 1. **Default Format** // Name: // Author: // Description: <summary><

javascript name vs ID

戏子无情 提交于 2019-12-01 04:20:58
As far as I know there are two ways to get the value from a textbox either document.formName.textboxName.value; or document.getElementbyId('textboxId').value; As I understand using form name would mean I have less code to write, as name can be used for posting data and getting the value (apart from using ajax). As where if I was just posting using a standard form I would use name to post but I cannot use id ? e.g. in php I would use $_POST['texboxName']; If I where to have and ID on the textbox I cannot get the value using php ? Which is the standard recommened way of doing this, and is using

Why is using exit() considered bad? [duplicate]

谁说我不能喝 提交于 2019-12-01 04:10:58
This question already has an answer here: How to end C++ code 14 answers I'm reading this question and there is an answer that explains why using exit() is bad because: You will end up having multiple exit points from the program It makes code more convoluted (like using goto) It cannot release memory allocated at runtime I should clarify that I'm using Qt, so the code is already a bit "convoluted" since I'm taking advantage of signals and slots. That being said, for issue #1, I see it's related to #2, but my code currently attempts to avoid usage of exit() because I was told it would make my

Which is the best, standard (and hopefully free) C++ compiler? [closed]

馋奶兔 提交于 2019-12-01 04:06:50
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . Saludos a todos en stackoverflow.com!! So... I'm a C++ newbie currently taking the subject of Data Structures, and I want to consult