standards

How do I write in-code comments and documentation in a proper way? Is there any standard for this? [closed]

依然范特西╮ 提交于 2019-12-05 12:06:51
I want to add documentation in my code by means of comment lines. Is there any standard format for this? For example, consider the code below: class Arithmetic { // This method adds two numbers, and returns the result. // dbNum1 is the first number to add, and dbNum2 is second. // The returning value is dbNum1+dbNum2. static double AddTwoNumbers(double dbNum1, double dbNum2); } For this example code, is there any better way of writing the comment lines? For c++ there isn't a standard, like javadoc, but certain documentation tools are popular and common to use. Off the top of my head, I can

Strict-aliasing and pointer to union fields

旧城冷巷雨未停 提交于 2019-12-05 11:56:02
I've got a question about strict-aliasing rules, unions and standard. Assume we have the following code: #include <stdio.h> union { int f1; short f2; } u = {0x1}; int * a = &u.f1; short * b = &u.f2; int main() { u.f1 = 1; *a += 1; u.f2 = 2; *b *= 2; printf( "%d %hd\n", *a, *b); return 0; } Now let's look how it works: $ gcc-5.1.0-x86_64 t.c -O3 -Wall && ./a.out 2 4 $ gcc-5.1.0-x86_64 t.c -O3 -Wall -fno-strict-aliasing && ./a.out 4 4 We can see that strict-aliasing breaks dependencies. Moreover it seems to be a correct code without breaking strict-aliasing rule. Does it turn out than in case of

Why are function argument names unimportant in c++ declarations?

六月ゝ 毕业季﹏ 提交于 2019-12-05 06:57:59
Function argument names in declarations (that most likely reside in the header file) are seemingly completely ignored by the compiler. What are the reasons for allowing the following to compile using either declaration version 1 or 2? implementation void A::doStuff(int numElements, float* data) { //stuff } declaration - Version 1 class A { public: void doStuff(int numElements, float* data); } declaration - Version 2 class A { public: void doStuff(int, float*); } The compiler only needs to know what kind of arguments the method requires. It's unimportant for the compiler how you call them. The

Where are ioctl parameters (such as 0x1268 / BLKSSZGET) actually specified?

点点圈 提交于 2019-12-05 05:35:16
This question was migrated from Unix & Linux Stack Exchange because it can be answered on Stack Overflow. Migrated 6 years ago . I am looking for a definitive specification describing the expected arguments and behavior of ioctl 0x1268 (BLKSSZGET). This number is declared in many places (none of which contain a definitive reference source), such as linux/fs.h , but I can find no specification for it. Surely, somebody at some point in the past decided that 0x1268 would get the physical sector size of a device and documented that somewhere. Where does this information come from and where can I

C++ Standard Layout and References

喜你入骨 提交于 2019-12-05 05:14:56
According to the C++ standard: A standard-layout class is a class that: —has no non-static data members of type non-standard-layout class (or array of such types) or reference. What property(ies) of references prevent classes with reference members from being included in the definition of a standard layout class? A standard layout class is all about having a well defined layout for a particular type in memory . In C++, references aren't objects so don't have any storage that can be accessed in a well defined way by a conforming program even though the implementation will usually have to have

Protected properties prefixed with underscores

。_饼干妹妹 提交于 2019-12-05 04:30:36
Like: public $foo = null, $bar = 10; protected $_stuff = null, $_moreStuff = 5; A lot of people seem to do this. Why? Isn't this inconsistent naming (like some PHP functions are :))? It really comes down to one thing: personal preference. I, personally, am also one who uses that naming convention. Prefixing anything that is protected or private with an underscore, be it a variable or a function, lets myself and any other programmer who I regularly work with know that that variable is global and will not be accessible outside of the current class/context. An example that helps clarify the use

AmazonS3: custom error pages

不问归期 提交于 2019-12-05 03:42:00
I am planning to share URLs (time limited) for private objects. Is there a way to set custom error pages for 404/403 http responses ? Yes, it's possible, see this announcement . In the Developer guide there is a paragraph about "Custom Error Document Support" where I read the following sentence. You can optionally provide a custom error document with a user-friendly error message and with additional help. You provide this custom error document as part of adding website configuration to your bucket. Amazon S3 returns your custom error document for only the HTTP 4XX class of error codes. How to

Auto with uniform initialization expands to unexpected type

强颜欢笑 提交于 2019-12-05 03:32:05
问题 Consider this short program compiled with GCC 4.7.2 g++ -std=c++11 test.cc #include <memory> #include <queue> struct type{ type(int a) : v(a) {} int v; }; typedef std::shared_ptr<type> type_ptr; int main(){ int value = 3; std::queue<type_ptr> queue; auto ptr{std::make_shared<type>(value)}; queue.push(ptr); } The compiler outputs the following errors: src/test.cc: In function ‘int main()’: src/test.cc:15:17: error: no matching function for call to ‘std::queue<std::shared_ptr<type> >::push(std:

Will a C conditional always return 1 or 0?

狂风中的少年 提交于 2019-12-05 02:12:41
Do C conditional statements always return [1 or 0], or do they return [0 or 'something other than zero']. I ask because: pseudo code - foo(address, shouldSend): register >>= 1 register <<= 1 // to clear bit in first position register |= shouldSend // to signal whether it should send or not the problem occurs if somebody passin IN a shouldSend value of true greater than one (as only 0 is false and all else is true, technically this is valid). since i am directly OR'ing the truth value of shouldSend with the register, it better not be say 0xFF! i already have a solution, so the question is more

How does the current working draft c++ differ from the current standard

匆匆过客 提交于 2019-12-05 01:39:15
问题 From searching for a PDF version of the standard I eventually came this link to the wording draft of the C++ standard from 2011. I realise I can buy a physical copy of the final standard but I'd sooner have a PDF I could easily search and refer to. What I'd like to know is, where can I find the differences list between this draft (assuming there are no other pre-ratification drafts) and the published standard? Is this draft sufficiently complete to use for casual reference? EDIT: link updated