Better `static` keywords

This commit is contained in:
gingerBill 2015-11-17 23:45:30 +00:00
parent 8fbff6e5bb
commit c01deefae5
2 changed files with 29 additions and 27 deletions

35
gb.hpp
View File

@ -1,8 +1,9 @@
// gb.hpp - v0.21 - public domain C++11 helper library - no warranty implied; use at your own risk
// gb.hpp - v0.21a - public domain C++11 helper library - no warranty implied; use at your own risk
// (Experimental) A C++11 helper library without STL geared towards game development
/*
Version History:
0.21a - Better `static` keywords
0.21 - Separate Math Library
0.20a - #ifndef for many macros
0.20 - Angle
@ -72,10 +73,10 @@ Context:
// NOTE(bill): Because static means three different things in C/C++
// Great Design(!)
#ifndef global
#define global static
#define internal static
#define local_persist static
#ifndef global_variable
#define global_variable static
#define internal_linkage static
#define local_persist static
#endif
#if defined(_MSC_VER)
@ -536,7 +537,7 @@ template <typename T> struct Remove_Reference_Def<T&> { using Type = T; };
template <typename T> struct Remove_Reference_Def<T&&> { using Type = T; };
template <typename T> using Remove_Reference = typename Remove_Reference_Def<T>::Type;
template <typename T, T v> struct Integral_Constant { global const T VALUE = v; using Value_Type = T; using Type = Integral_Constant; };
template <typename T, T v> struct Integral_Constant { global_variable const T VALUE = v; using Value_Type = T; using Type = Integral_Constant; };
template <typename T, usize N = 0> struct Extent : Integral_Constant<usize, 0> {};
template <typename T> struct Extent<T[], 0> : Integral_Constant<usize, 0> {};
@ -2369,7 +2370,7 @@ destroy(Thread* t)
semaphore::destroy(&t->semaphore);
}
internal s32
internal_linkage s32
run(Thread* t)
{
semaphore::post(&t->semaphore);
@ -2377,7 +2378,7 @@ run(Thread* t)
}
#if defined(GB_SYSTEM_WINDOWS)
internal DWORD WINAPI
internal_linkage DWORD WINAPI
thread_proc(void* arg)
{
Thread* t = static_cast<Thread*>(arg);
@ -2386,7 +2387,7 @@ thread_proc(void* arg)
}
#else
internal void*
internal_linkage void*
thread_proc(void* arg)
{
local_persist s32 result = -1;
@ -2704,7 +2705,7 @@ void append(String* str, const void* other, Size other_len)
namespace impl
{
// NOTE(bill): ptr _must_ be allocated with Allocator* a
internal inline void*
internal_linkage inline void*
string_realloc(Allocator* a, void* ptr, usize old_size, usize new_size)
{
if (!ptr)
@ -3024,7 +3025,7 @@ adler32(const void* key, u32 num_bytes)
return (b << 16) | a;
}
global const u32 GB_CRC32_TABLE[256] = {
global_variable const u32 GB_CRC32_TABLE[256] = {
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
@ -3091,7 +3092,7 @@ global const u32 GB_CRC32_TABLE[256] = {
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d,
};
global const u64 GB_CRC64_TABLE[256] = {
global_variable const u64 GB_CRC64_TABLE[256] = {
0x0000000000000000ull, 0x42F0E1EBA9EA3693ull, 0x85E1C3D753D46D26ull, 0xC711223CFA3E5BB5ull,
0x493366450E42ECDFull, 0x0BC387AEA7A8DA4Cull, 0xCCD2A5925D9681F9ull, 0x8E224479F47CB76Aull,
0x9266CC8A1C85D9BEull, 0xD0962D61B56FEF2Dull, 0x17870F5D4F51B498ull, 0x5577EEB6E6BB820Bull,
@ -3378,7 +3379,7 @@ namespace time
{
#if defined(GB_SYSTEM_WINDOWS)
internal LARGE_INTEGER
internal_linkage LARGE_INTEGER
win32_get_frequency()
{
LARGE_INTEGER f;
@ -3400,7 +3401,7 @@ now()
// Get the frequency of the performance counter
// It is constant across the program's lifetime
internal LARGE_INTEGER s_frequency = win32_get_frequency();
local_persist LARGE_INTEGER s_frequency = win32_get_frequency();
// Get the current time
LARGE_INTEGER t;
@ -3514,7 +3515,7 @@ namespace file
{
#if defined(GB_SYSTEM_WINDOWS)
internal char*
internal_linkage char*
duplicate_string(const char* string)
{
usize len = strlen(string);
@ -3547,7 +3548,7 @@ new_from_fd(File* file, uintptr h, const char* name)
return true;
}
internal bool
internal_linkage bool
win32_open_file(File* file, const char* name, u32 flag, u32 perm)
{
// TODO(bill):
@ -3590,7 +3591,7 @@ close(File* file)
return false;
}
// internal bool
// internal_linkage bool
// win32_pread(File* file, void* buffer, u32 bytes_to_read, s64 offset)
// {
// mutex::lock(&file->mutex);

View File

@ -1,9 +1,10 @@
// gb_math.hpp - v0.02 - public domain C++11 math library - no warranty implied; use at your own risk
// gb_math.hpp - v0.02a - public domain C++11 math library - no warranty implied; use at your own risk
// A C++11 math library geared towards game development
// This is meant to be used the gb.hpp library but it doesn't have to be
/*
Version History:
0.02a - Better `static` keywords
0.02 - More Angle Units and templated min/max/clamp/lerp
0.01 - Initial Version
@ -45,10 +46,10 @@ Context:
// NOTE(bill): Because static means three different things in C/C++
// Great Design(!)
#ifndef global
#define global static
#define internal static
#define local_persist static
#ifndef global_variable
#define global_variable static
#define internal_linkage static
#define local_persist static
#endif
#if defined(_MSC_VER)
@ -2297,9 +2298,9 @@ template <typename T>
inline void
swap(T* a, T* b)
{
T c = gb::move(*a);
*a = gb::move(*b);
*b = gb::move(c);
T c = __GB_NAMESPACE_PREFIX::move(*a);
*a = __GB_NAMESPACE_PREFIX::move(*b);
*b = __GB_NAMESPACE_PREFIX::move(c);
}
template <typename T, usize N>
@ -3651,7 +3652,7 @@ uniform_f64(Random* r, f64 min_inc, f64 max_inc)
}
global s32 g_perlin_randtab[512] =
global_variable s32 g_perlin_randtab[512] =
{
23, 125, 161, 52, 103, 117, 70, 37, 247, 101, 203, 169, 124, 126, 44, 123,
152, 238, 145, 45, 171, 114, 253, 10, 192, 136, 4, 157, 249, 30, 35, 72,
@ -3690,7 +3691,7 @@ global s32 g_perlin_randtab[512] =
};
internal f32
internal_linkage f32
perlin_grad(s32 hash, f32 x, f32 y, f32 z)
{
local_persist f32 basis[12][4] =