Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
int a[100][100]; | ||
int (*getArray())[100] { | ||
return a; | ||
} | ||
int main() { | ||
int (*pArray)[100] = getArray(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <Windows.h> | ||
#include <cassert> | ||
#include <cstdio> | ||
|
||
template <typename F> | ||
struct ScopeExit { | ||
ScopeExit(F f) : f(f) {} | ||
~ScopeExit() { f(); } | ||
F f; | ||
}; | ||
|
||
template <typename F> | ||
ScopeExit<F> MakeScopeExit(F f) { | ||
return ScopeExit<F>(f); | ||
}; | ||
#define STRING_JOIN2(arg1, arg2) DO_STRING_JOIN2(arg1, arg2) | ||
#define DO_STRING_JOIN2(arg1, arg2) arg1 ## arg2 | ||
#define SCOPE_EXIT(code) \ | ||
auto STRING_JOIN2(scope_exit_, __LINE__) = MakeScopeExit([&](){code;}) | ||
|
||
struct OverlappedBuffer { | ||
OVERLAPPED o; | ||
char b[64]; | ||
}; | ||
|
||
int main() { | ||
|
||
auto fn = L"C:\\Users\\skyshaw\\Desktop\\data.txt"; | ||
auto f = CreateFile(fn, GENERIC_READ, FILE_SHARE_READ, nullptr, | ||
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); | ||
assert(fn); | ||
SCOPE_EXIT(CloseHandle(f)); | ||
|
||
OverlappedBuffer ob = {}; | ||
ReadFileEx(f, ob.b, sizeof(ob.b), &ob.o, [](DWORD e, DWORD c, OVERLAPPED* o) { | ||
assert(e == ERROR_SUCCESS); | ||
auto ob = reinterpret_cast<OverlappedBuffer*>(o); | ||
std::printf("> %.*s\n", c, ob->b); | ||
}); | ||
SleepEx(INFINITE, true); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include <Windows.h> | ||
#include <cassert> | ||
#include <cstdio> | ||
|
||
template <typename F> | ||
struct ScopeExit { | ||
ScopeExit(F f) : f(f) {} | ||
~ScopeExit() { f(); } | ||
F f; | ||
}; | ||
|
||
template <typename F> | ||
ScopeExit<F> MakeScopeExit(F f) { | ||
return ScopeExit<F>(f); | ||
}; | ||
#define STRING_JOIN2(arg1, arg2) DO_STRING_JOIN2(arg1, arg2) | ||
#define DO_STRING_JOIN2(arg1, arg2) arg1 ## arg2 | ||
#define SCOPE_EXIT(code) \ | ||
auto STRING_JOIN2(scope_exit_, __LINE__) = MakeScopeExit([&](){code;}) | ||
|
||
|
||
int main() { | ||
auto t = CreateThread(nullptr, 0, [](void*) -> DWORD { | ||
auto fn = L"C:\\Users\\skyshaw\\Desktop\\data.txt"; | ||
auto f = CreateFile(fn, GENERIC_READ, FILE_SHARE_READ, nullptr, | ||
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); | ||
assert(fn); | ||
SCOPE_EXIT(CloseHandle(f)); | ||
char b[64]; | ||
DWORD c; | ||
ReadFile(f, b, sizeof(b), &c, nullptr); | ||
std::printf("> %.*s\n", c, b); | ||
return 0; | ||
}, nullptr, 0, nullptr); | ||
assert(t); | ||
WaitForSingleObject(t, INFINITE); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include <Windows.h> | ||
#include <cassert> | ||
#include <cstdio> | ||
|
||
template <typename F> | ||
struct ScopeExit { | ||
ScopeExit(F f) : f(f) {} | ||
~ScopeExit() { f(); } | ||
F f; | ||
}; | ||
|
||
template <typename F> | ||
ScopeExit<F> MakeScopeExit(F f) { | ||
return ScopeExit<F>(f); | ||
}; | ||
#define STRING_JOIN2(arg1, arg2) DO_STRING_JOIN2(arg1, arg2) | ||
#define DO_STRING_JOIN2(arg1, arg2) arg1 ## arg2 | ||
#define SCOPE_EXIT(code) \ | ||
auto STRING_JOIN2(scope_exit_, __LINE__) = MakeScopeExit([&](){code;}) | ||
|
||
|
||
int main() { | ||
auto fn = L"C:\\Users\\skyshaw\\Desktop\\data.txt"; | ||
auto f = CreateFile(fn, GENERIC_READ, FILE_SHARE_READ, nullptr, | ||
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); | ||
assert(fn); | ||
SCOPE_EXIT(CloseHandle(f)); | ||
|
||
char b[64]; | ||
DWORD c; | ||
ReadFile(f, b, sizeof(b), &c, nullptr); | ||
std::printf("> %.*s\n", c, b); | ||
return 0; | ||
} |