Commits

jsagevid committed 7f89623

Added Visual Studio support.

  • Participants
  • Parent commits 008bdde

Comments (0)

Files changed (5)

 		return (const void*)((const char *)p + bytes);
 	}
 
-	inline template<class T> T *memory::pointer_add(T *p, uint32_t bytes)
-	{
-		return (T*)((char *)p + bytes);
-	}
-
-	inline template<class T> const T *memory::pointer_add(const T *p, uint32_t bytes)
-	{
-		return (const T*)((char *)p + bytes);
-	}
-
 	/// Returns the result of moving p back by the specified number of bytes
 	inline void *memory::pointer_sub(void *p, uint32_t bytes)
 	{

File snprintf_msvc.h

+#pragma once
+
+#if defined(_MSC_VER)
+	#include <stdarg.h>
+	#include <stdio.h>
+
+	inline int vsnprintf_compat(char* buffer, size_t size, const char* format, va_list args)
+	{
+		int result = -1;
+		if (size > 0)
+			result = _vsnprintf_s(buffer, size, _TRUNCATE, format, args);
+		if (result == -1)
+			return _vscprintf(format, args);
+	
+		return result;	
+	}
+
+	inline int snprintf_compat(char* buffer, size_t size, const char* format, ...)
+	{
+		va_list args;
+		va_start(args, format);
+		int result = vsnprintf_compat(buffer, size, format, args);
+		va_end(args);
+		return result;
+	}
+
+	#define snprintf snprintf_compat
+	#define vsnprintf vsnprintf_compat
+#endif

File string_stream.h

 #include <string.h>
 #include <stdio.h>
 
+#include "snprintf_msvc.h"
+
 namespace foundation
 {
 	/// Functions for operating on an Array<char> as a stream of characters,
 
 #include <stdint.h>
 
-#ifndef alignof
+#if defined(_MSC_VER)
+	#define _ALLOW_KEYWORD_MACROS
+#endif
+	
+#if !defined(alignof)
 	#define alignof(x) __alignof(x)
-#endif
+#endif

File unit_test.cpp

 
 	void test_pointer_arithmetic()
 	{
-		const char check = 0xfe;
+		const char check = (char)0xfe;
 		const unsigned test_size = 128;
 
 		TempAllocator512 ta;