standards

Whats the standard way of getting the last insert id?

試著忘記壹切 提交于 2019-11-30 20:09:03
What's the sql standard to get the last inserted id? If there is such a thing. mysql: LAST_INSERT_ID() postgresql: ... RETURNING f_id mssql: SCOPE_IDENTITY() ... more examples here ... I mean, all databases have different implementations for that, there isn't a standard for such a common task? RichardTheKiwi See this answer Retrieve inserted row ID in SQL In short, there is no cross database way to do this, except MAX(ID) - but that is not a guaranteed result and has many many pitfalls, e.g. other inserts can come between last insert and max query cannot be used with high transaction tables

What is the preferred declaration convention for objects or arrays: const or let?

三世轮回 提交于 2019-11-30 20:07:19
问题 I'm not asking what's technically possible; I know you can do const a = []; const b = {}; a.push['sup']; b.test = 'earth'; What I'm wondering is whether there's any convention for preferring let over const when it comes to arrays and objects that will have their internals modified. If you see an object declared with const , do you assume the intention was for the object to be immutable, and would you have preferred to see let instead, or, since some linters (like tslint) have a problem with

Are brackets in the WHERE clause standard sql

我是研究僧i 提交于 2019-11-30 19:47:01
The course that I am currently doing uses brackets in its WHERE clauses like so: SELECT bar FROM Foo WHERE (CurrentState = 'happy'); Is this standard sql ? If not then why use them? Doesn't seem to be used in the Date & Darwen book I have. EDIT Just to clarify - I'm referring to 1992 sql standards Yes. You can use parenthesis to bind components of where clauses. This isn't necessary in your example, but if you had multiple and and or components, you might need parenthesis to either ensure correct order of operations or simply to self-document the query. Example 1: select * from foo where

What does “char (*a)[12]” mean?

為{幸葍}努か 提交于 2019-11-30 18:32:46
问题 Is this from the C standard? 回答1: Because declarations in C follow the operator precedence rules (ie array subscription is evaluated before indirection), you'll need parens to declare pointers to array types. In many use cases, there's not really any practical benefit over using a plain char * , except that it's a way to enforce the array size, especially when used as a function parameter: void foo(char bar[42]); is equivalent to void foo(char *bar); and accepts any char * , whereas void foo

What's the difference between “dead code” and “unreachable code”?

断了今生、忘了曾经 提交于 2019-11-30 17:32:20
I thought those terms where synonymous, but a note in MISRA regarding dead code indicates this to be wrong? What's the difference? Is one a subset of the other? Dead code - code that is executed but redundant, either the results were never used or adds nothing to the rest of the program. Wastes CPU performance. function(){ // dead code since it's calculated but not saved or used anywhere a + b; } Unreachable code - code that will never be reached regardless of logic flow. Difference is it's not executed. function(){ return x; // unreachable since returned a = b + c; } Dead Code Code that

Constant array types in C, flaw in standard?

随声附和 提交于 2019-11-30 17:29:32
Paragraph 6.7.3.8 of the C99 spec states If the specification of an array type includes any type qualifiers, the element type is so-qualified, not the array type. If the specification of a function type includes any type qualifiers, the behavior is undefined. In the rationale (logical page 87, physical page 94), an example of casting a flat pointer to a (variable length) array pointer is given. void g(double *ap, int n) { double (*a)[n] = (double (*)[n]) ap; /* ... */ a[1][2] /* ... */ } Certainly if the array ap is not modified within the function, it should be marked const, however the cast in

Is sizeof(size_t) == sizeof(void*) always true?

て烟熏妆下的殇ゞ 提交于 2019-11-30 17:17:07
Does the C99/C++11 standard guarantee that sizeof(size_t) == sizeof(void*) is always true? size_t f(void* p) { return (size_t)(p); // Is it safe? } void* f(size_t n) { return (void*)(n); // Is it safe? } No, that is not guaranteed. Use intptr_t or uintptr_t to safely store a pointer in an integer. There are/were architectures where it makes sense for that to be false, such as the segmented DOS memory model. There the memory was structured in 64k segments - an object could never be larger than a segment, so 16-bit size_t would be enough. However, a pointer had "segment" and "offset" parts, so

Which browsers support the <embed> and <object> tags?

爱⌒轻易说出口 提交于 2019-11-30 17:09:14
I am working on a department website that needs to be standards compliant (xhtml 1.0 transitional), but embedded flash keeps breaking the validation. We use the <embed> tag because we need to support most major browsers. We can't use external tools, since the site is managed through a system and the admins don't like us putting extra tools (like JavaScript libraries etc) that could interfere with their template engine. How widely supported is the object tag? Is it safe to use only the <object> tag and remove the <embed> tag all together? <embed> is invalid in XHTML 1.0 and HTML 4, but it’s

interfacing with stdbool.h C++

南楼画角 提交于 2019-11-30 16:44:27
问题 In a project I am interfacing between C++ and a C library that uses stdbool.h defined as such. #ifndef _STDBOOL_H #define _STDBOOL_H /* C99 Boolean types for compilers without C99 support */ /* http://www.opengroup.org/onlinepubs/009695399/basedefs/stdbool.h.html */ #if !defined(__cplusplus) #if !defined(__GNUC__) /* _Bool builtin type is included in GCC */ typedef enum { _Bool_must_promote_to_int = -1, false = 0, true = 1 } _Bool; #endif #define bool _Bool #define true 1 #define false 0

C++ empty-paren member initialization - zeroes out memory?

孤街醉人 提交于 2019-11-30 15:49:40
I originally wrote some code like this: class Foo { public: Foo() : m_buffer() {} private: char m_buffer[1024]; }; Someone who is smarter than me said that having the m_buffer() initializer would zero out the memory. My intention was to leave the memory uninitialized. I didn't have time to discuss it further, but it piqued my curiosity. Previously, I had thought it was wise to always list each member in the initializer list. Could someone please describe this behavior further? 1) Why does the empty-paren initializer fill in memory? 2) Does it only hold for POD datatypes? I heard that it was so