standards

Can a C/C++ compiler legally cache a variable in a register across a pthread library call?

妖精的绣舞 提交于 2019-12-04 19:16:17
问题 Suppose that we have the following bit of code: #include <pthread.h> #include <stdio.h> #include <stdlib.h> void guarantee(bool cond, const char *msg) { if (!cond) { fprintf(stderr, "%s", msg); exit(1); } } bool do_shutdown = false; // Not volatile! pthread_cond_t shutdown_cond = PTHREAD_COND_INITIALIZER; pthread_mutex_t shutdown_cond_mutex = PTHREAD_MUTEX_INITIALIZER; /* Called in Thread 1. Intended behavior is to block until trigger_shutdown() is called. */ void wait_for_shutdown_signal() {

Why is it forbidden to open multiple namespaces at a stretch?

╄→尐↘猪︶ㄣ 提交于 2019-12-04 17:24:38
问题 It's possible to do using namespace foo::bar; (i.e., using the inner namespace without using the outer namespace first / at all), why does the standard forbid to do the following? namespace foo::bar { // open nested namespace bar in foo and extend it... } I'm not looking for a workaround, just a possible rational on why this isn't allowed. 回答1: I'm not sure "forbidden" is the right word - maybe it was just an oversight. It's a fairly small nice-to-have which isn't really a big deal. You could

Use Python standard logging in Celery

纵然是瞬间 提交于 2019-12-04 17:04:12
问题 I have to implement Celery in a pre-existing system. The previous version of the system already used Python standard logging. My code is similar to the code below. Process one and process two are non-Celery functions, which are logging everywhere. We are using the logging to track data loss if something bad happens. @task def add(x,y): process_one(x,y) process_two(x,y) How can I implement Celery and use the Python standard logging instead Celery logging, so our old logging system is not lost?

Does the C++11 standard guarantee identical random numbers for the same seed across implementations?

房东的猫 提交于 2019-12-04 16:41:50
问题 For example if I instantiate a std::mt19937 with the exact same seed and parameters under GCC and under MSVC, should I get the same sequence of random numbers? If so I assume this property would hold for mersenne_twister_engine in general since mt19937 is just one with specific parameters. This is not true for rand() in C. It looks like the standard documents the transformations applied in terms of specific code, so I suspect it should always be the same, but the devil is in the details...

W3C document states

…衆ロ難τιáo~ 提交于 2019-12-04 15:59:07
Within the standards that W3C create, do they have a set of states they go through before they are a standard and what are those states ? For example HTML 5.1 currently is in Working Draft . The process is typically linked in the section "Status of This Document". For HTML 5.1, it says : This document is governed by the 1 August 2014 W3C Process Document . This links to the World Wide Web Consortium Process Document from 2014-08-01 (the latest version is always accessible from http://www.w3.org/Consortium/Process/ ). For technical reports that should become Recommendations, this is the process

Does standard C++11 guarantee that temporary object passed to a function will have been created before function call?

我只是一个虾纸丫 提交于 2019-12-04 14:01:05
Does standard C++11 guarantee that all 3 temporary objects have been created before the beginning performe the function? Even if temporary object passed as: object rvalue-reference passed only member of temporary object http://ideone.com/EV0hSP #include <iostream> using namespace std; struct T { T() { std::cout << "T created \n"; } int val = 0; ~T() { std::cout << "T destroyed \n"; } }; void function(T t_obj, T &&t, int &&val) { std::cout << "func-start \n"; std::cout << t_obj.val << ", " << t.val << ", " << val << std::endl; std::cout << "func-end \n"; } int main() { function(T(), T(), T()

Does using ignore(numeric_limits<streamsize>::max()) in the IOStreams library handle arbitrarily massive streams?

我们两清 提交于 2019-12-04 12:24:24
In the C++ standard (section 27.6.1.3\24), for the istream ignore() function in the IOStreams library, it implies that if you supply an argument for 'n' of numeric_limits::max() , it will continue to ignore characters forever up until the delimiter is found, even way beyond the actual max value for streamsize (i.e. the 'n' argument is interpreted as infinite). For the gcc implementation this does indeed appear to be how ignore() is implemented, but I'm still unclear as to whether this is implementation specific, or mandated by the standard. Can someone who knows this well confirm that this is

Which C++ draft?

点点圈 提交于 2019-12-04 11:26:43
I am interested in having a current C++ standard and I am a little bit confused with links at http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/ . What is supposed to be the new version? What title should I look for? Is it " Working Draft, Standard for Programming Language C++ " or " Programming Languages — C++ "? What's the difference between these papers? Why N4141 paper is password-protected while newer N4296 is not? In question Where do I find the current C or C++ standard documents? there's a good list of drafts, but I still can't tell what is the "stable" version of draft, i.e.

operator new with empty exception-specification calling constructor when allocation returns 0

让人想犯罪 __ 提交于 2019-12-04 11:15:42
I have the following declaration: void * operator new (size_t s, PersistentMemory * m) throw() {return m->allocatePersistentMemory(s);} I'm testing memory exhaustion on start-up, which results in m->allocatePersistentMemory(s); returning 0. New then calls the constructor with a null pointer for this However, based on 3.7.3.1 paragraph 3 of C++ 2003 standard: An allocation function that fails to allocate storage can invoke the currently installed new_handler (18.4.2.2), if any. [Note: A program-supplied allocation function can obtain the address of the currently installed new_handler using the

Does redefining a function from the standard library violate the one-definition rule?

不羁的心 提交于 2019-12-04 10:59:33
#include <cmath> double log(double) {return 1.0;} int main() { log(1.0); } Suppose the function log() in <cmath> is declared in global namespace (this is unspecified in fact, and we just make this assumption), then it refers to the same function as the log() function we defined. So does this code violate the one-definition rule (see here , since no diagnostic required, this code may compile in some compiler and we cannot assert if it is correct)? Note : After recent edits, this is not a duplicate of: What exactly is One Definition Rule in C++? Typical scenario. If extern "C" double log(double)