standards

Bit manipulations good practices

两盒软妹~` 提交于 2019-12-02 23:25:21
As a beginner C programmer, I am wondering, what would be the best easy-to-read and easy-to-understand solution for setting control bits in a device. Are there any standards ? Any example code to mimic? Google didn't give any reliable answer. For example, I have a control block map: The first way I see would be to simply set the needed bits. It requires a bunch of explanations in comments and seems to be not all that professional. DMA_base_ptr[DMA_CONTROL_OFFS] = 0b10001100; The second way I see is to create a bit field. I'm not sure if this is the one should I stick to, since I never

What size should I allow for strerror_r?

喜夏-厌秋 提交于 2019-12-02 21:53:17
The OpenGroup POSIX.1-2001 defines strerror_r , as does The Linux Standard Base Core Specification 3.1 . But I can find no reference to the maximum size that could be reasonably expected for an error message. I expected some define somewhere that I could put in my code but there is none that I can find. The code must be thread safe. Which is why strerror_r is used and not strerror. Does any one know the symbol I can use? I should I create my own? Example int result = gethostname(p_buffy, size_buffy); int errsv = errno; if (result < 0) { char buf[256]; char const * str = strerror_r(errsv, buf,

What can you do in C without “std” includes? Are they part of “C,” or just libraries?

谁说我不能喝 提交于 2019-12-02 21:38:00
I apologize if this is a subjective or repeated question. It's sort of awkward to search for, so I wasn't sure what terms to include. What I'd like to know is what the basic foundation tools/functions are in C when you don't include standard libraries like stdio and stdlib . What could I do if there's no printf() , fopen() , etc? Also, are those libraries technically part of the "C" language, or are they just very useful and effectively essential libraries? The C standard has this to say (5.1.2.3/5): The least requirements on a conforming implementation are: — At sequence points, volatile

What is the difference between the standard library and the standard template library?

左心房为你撑大大i 提交于 2019-12-02 21:29:10
I keep seeing reference to both the C++ standard Library and the C++ Standard Template Library (STL). What is the difference between them? Wikipedia mentions that they share some headers but that's about it. The Standard Template Library (STL) is a library of containers, iterators, algorithms, and function objects, that was created by Alexander Stepanov; the SGI website has the canonical implementation and documentation. The standard library is the library that is part of C++; it includes most of the Standard Template Library (STL). In common usage, "STL" is also used to refer to the parts of

C11 Standard docs

♀尐吖头ヾ 提交于 2019-12-02 21:02:55
Starting from this SO protected question I'm trying to understand what the difference between those documents: 9899 2012 costs $60 9899 2011 costs $265 As you can see those documents have very different prices and I don't know if the cheaper one is valid or is something like draft or cut copy of the real standard. Did someone buy the INCITS one? EDIT As @Chqrlie pointed out: What is the difference between the ANSI and ISO official documents available for a free and the final draft freely accessible from the official website at open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf LPs I finally got

Standards for Date/Time addition?

China☆狼群 提交于 2019-12-02 20:48:31
I'm looking for standards for Date/Time addition. I haven't been able to find any. In particular I'm hoping to find a spec that defines what should happen when you add a month to a date like January 31st. Is the right answer February 28th(/29th)? March 1st? March 2nd? I've seen inconsistent implementations between different tools (PHP & MySQL in this case), and I'm trying to find some sort of standards to base my work on. Differing Results: PHP $end = strtotime("+1 month", 1314835200); //1317513600 Sat, 01 Oct 2011 20:00:00 -0400 MySQL SELECT UNIX_TIMESTAMP(DATE_ADD(FROM_UNIXTIME(1314835200),

Why a virtual call to a pure virtual function from a constructor is UB and a call to a non-pure virtual function is allowed by the Standard?

余生颓废 提交于 2019-12-02 20:41:32
From 10.4 Abstract Classes parag. 6 in the Standard : "Member functions can be called from a constructor (or destructor) of an abstract class; the effect of making a virtual call to a pure virtual function directly or indirectly for the object being created (or destroyed) from such a constructor (or destructor) is undefined." Assuming that a call to a non-pure virtual function from a constructor (or destructor), is allowed by the Standard, why the difference ? [EDIT] More standards quotes about pure virtual functions: § 10.4/2 A virtual function is specified pure by using a pure-specifier (9.2

Why Doesn't jQuery use JSDoc? [closed]

一曲冷凌霜 提交于 2019-12-02 20:14:00
Or do they and it's just not in the source? I'd really like to get something that will stop js-doc-toolkit from freaking out each time it parses jQuery. It also means I can't properly document any code using jQuery as a dependency without at least putting some boilerplate js-doc blocks, which fail to properly document jQuery's structure. Is there a common solution I'm not aware of? I have tried googling, btw. Nick Craver I'll take a shot in the dark here since I can't speak for the jQuery team of why I wouldn't use JSDoc. JSDoc, at least the last time I checked, didn't have any clean way to

Why do primitive and user-defined types act differently when returned as 'const' from a function?

巧了我就是萌 提交于 2019-12-02 20:03:54
#include <iostream> using namespace std; template<typename T> void f(T&&) { cout << "f(T&&)" << endl; } template<typename T> void f(const T&&) { cout << "f(const T&&)" << endl; } struct A {}; const A g1() { return {}; } const int g2() { return {}; } int main() { f(g1()); // outputs "f(const T&&)" as expected. f(g2()); // outputs "f(T&&)" not as expected. } The issue description is embedded in the code. My compiler is clang 5.0 . I just wonder: Why does C++ treat built-in types and custom types differently in such a case? I don't have a quote from the standard, but cppreference confirms my

Why does no database fully support ANSI or ISO SQL standards?

ぐ巨炮叔叔 提交于 2019-12-02 19:59:28
If I were designing a oil refinery, I wouldn't expect that materials from different vendors would not comply with published standards in subtle yet important ways. Pipework, valves and other components from one supplier would come with flanges and wall thicknesses to ANSI standards, as would the same parts from any other supplier. Interoperability and system safety is therefore assured. Why then are the common databases so choosy about which parts of the standards they adhere to, and why have no 100% standards-compliant systems come to the fore? Are the standards 'broken', lacking in scope or