Documentation of Win32 handles (consoles, {Get,Set}StdHandle, inheritance)
github.com2 pointsby ryanprichard0 comments
def foo(n: int):
pass
def bar():
foo("123")
It does detect this mismatch: def foo(n: int):
pass
foo("123") enum AnyKind { AnyInt, AnyDouble, AnyStr };
struct Any {
enum AnyKind kind;
union {
int i;
double d;
const char *s;
} u;
};
#define ANY(x) \
_Generic((x), \
int: (struct Any){ .kind = AnyInt, .u.i = (x) }, \
double: (struct Any){ .kind = AnyDouble, .u.d = (x) }, \
const char *: (struct Any){ .kind = AnyStr, .u.s = (x) })
int main() {
ANY(1);
ANY(1.0);
ANY("abc");
}
Clang gives errors like: error: initializing 'const char *' with an expression of incompatible type 'double'
This issue was discussed a bit on the GCC bugtracker: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64509 #define bar(...) (bar( \
sizeof((const char*[]) { NULL, __VA_ARGS__ }) / sizeof(const char*) - 1, \
(const char*[]) { NULL, __VA_ARGS__ } + 1))
bar() results in trailing commas. My impression is that C99 allows them in array initializers. (I saw an example in the n1256 C draft.) I don't recall whether C89 also had them. __VA_ARGS__ is expanded twice, but I think that's OK, because sizeof() only evaluates its operand when it has VLA type, and it never will. This code will work in MSVC 2013 (if not earlier).
The other interesting problems I found with that API were: (1) when editing an input line, EVENT_CONSOLE_CARET notifications were delayed, (2) if I hit ESC when editing an input line, the line would clear, but there'd be no update-region notification, and (3) it's impossible to distinguish between a call to ScrollConsoleScreenBuffer and the whole buffer scrolling because we've reached the end. ScrollConsoleScreenBuffer might scroll only part of the buffer.
winpty doesn't use the WinEvents API (yet), but it might be good enough to reduce polling when the console is idle.