standards

When a function has a specific-size array parameter, why is it replaced with a pointer?

拈花ヽ惹草 提交于 2019-12-16 18:34:28
问题 Given the following program, #include <iostream> using namespace std; void foo( char a[100] ) { cout << "foo() " << sizeof( a ) << endl; } int main() { char bar[100] = { 0 }; cout << "main() " << sizeof( bar ) << endl; foo( bar ); return 0; } outputs main() 100 foo() 4 Why is the array passed as a pointer to the first element? Is it a heritage from C? What does the standard say? Why is the strict type-safety of C++ dropped? 回答1: Yes it's inherited from C. The function: void foo ( char a[100]

What is the minimum size of an int in C++?

情到浓时终转凉″ 提交于 2019-12-14 04:22:49
问题 Cppreference.com claims: If no length modifiers are present, it's guaranteed to have a width of at least 16 bits. However, the latest standard draft only says: Plain ints have the natural size suggested by the architecture of the execution environment. With the footnote only adding that: int must also be large enough to contain any value in the range [INT_­MIN, INT_­MAX], as defined in the header <climits>. From these sections of the standards, it seems like int 's size is entirely

Equivalence of <limits> and <climits>

限于喜欢 提交于 2019-12-14 01:37:47
问题 Is this guaranteed to be always true: std::numeric_limits<int>::max() == INT_MAX What does C++ standard say about it? I could not find any reference in the standard that would explicitly state this, but I keep reading that those should be equivalent. What about C99 types that are not in C++98 standard for compilers that implement both C99 (at least long long part) and C++98? I am not sure whether there is any guarantee that this always holds true: std::numeric_limits<unsigned long long>::max(

Is iteration slower than linear code? Which one is preferable?

萝らか妹 提交于 2019-12-13 22:56:11
问题 This question was migrated from Software Engineering Stack Exchange because it can be answered on Stack Overflow. Migrated 7 years ago . I have a question in my mind from last many days, that while writing a code in ruby, is the linear code is faster and preferable than an iteration? Let me have an example. There is a block of code for same functionality written in two different ways: Way 1: ['dog', 'cat', 'tiger'].each do |pet_name| puts "I have many pets, one of them is #{pet_name}." end

C99 - vscanf for dummies? [closed]

拥有回忆 提交于 2019-12-13 20:34:11
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . I am sorry to bother S.O. with such a general request for information. I can find plenty of very terminology-heavy definitions of vscanf - but I can't find much in the way of concrete examples which will show

When may the dynamic type of a referred to object change?

二次信任 提交于 2019-12-13 17:03:53
问题 Let us begin with an example: #include <cstdio> struct Base { virtual ~Base() {} virtual void foo() = 0; }; struct P: Base { virtual void foo() override { std::printf("Hello, World!"); } }; struct N: Base { virtual void foo() override {} }; void magic(Base& b); // Example implementation that changes the dynamic type // { // void* s = dynamic_cast<void*>(&b); // b.~B(); // new (s) N(); // } int main() { std::aligned_storage<sizeof(P), alignof(P)> storage; void* s = static_cast<void*>(storage);

How can I understand what standard my libraries are and to what standard gcc compiles in my computer?

一笑奈何 提交于 2019-12-13 13:23:09
问题 This is from my terminal: Korays-MacBook-Pro:~ koraytugay$ gcc --version Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 6.1.0 (clang-602.0.49) (based on LLVM 3.6.0svn) Target: x86_64-apple-darwin14.3.0 Thread model: posix There are 3 C standards as far as I know, ANSI C, C99 and C11. How can I know which library I have and what my compiler supports? 回答1: You have to find the documentation for your compiler and

Why nested functions in C are against C standards

不羁的心 提交于 2019-12-13 06:51:33
问题 Nested functions(function declarations in block scope) are not allowed in C standards(ANSI[C89], C99, C11). But I couldn't find stating it in C standards. Edit : Why a function definition cannot be in a function definition(compound statement)? 回答1: There is a difference between a function declaration and a function definition . A declaration merely declares the existence of a function and a definition defines the function. int f(void) { /* ... */ } // function definition int f(void); //

Any standard format to describe time ranges as String? Want to use it for opening hours

拥有回忆 提交于 2019-12-13 05:45:33
问题 We want to use it for opening hours like... Mo 11:00-13:00 Tue 9:00-18:00 Update Now required: Wed 8:00-11:30, Wed 12:00-17:00 We have a Ruby based server and deliver JSON and XML to the clients. We follow the ActiveResource pattern, so that we can use plug ins in our clients That's our current proprietary approach: "availabilities":[{"end_time":"00:00","weekdays":"0,1,2,3,4,5,6","start_time":"00:00"}] 回答1: cron format was designed specifically for this, including relative dates like "from

Existing standard(s) for passing MIDI via OSC?

旧巷老猫 提交于 2019-12-13 02:32:42
问题 I am using OSC to feed into MIDI - so the many OSC controller apps can be used on standard MIDI kit. Just for 'proof of concept' I used this format:- /midi/note_on/<note-number> /midi/note_off/<note-number> /midi/control_change/<control>/<value> etc... Now it seems to be doable... is there already a standard I could steal for this? If not, I am happy to define one ;) Background: I am doing some WIFI OSC/MIDI stuff... A pyton script to act as MIDI WiFi server to receive midi/osc over IP (but