first commit
This commit is contained in:
33
Endian/C/CMakeLists.txt
Normal file
33
Endian/C/CMakeLists.txt
Normal file
@@ -0,0 +1,33 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
# Modify only these if one source file!
|
||||
project(CEndian)
|
||||
set(CURRENT_PROJECT_CODE_NAME endian)
|
||||
set(FILE_EXT c)
|
||||
# End
|
||||
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
set(CMAKE_C_STANDARD_REQUIRED True)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||
|
||||
# We want all the warnings and as errors enabled
|
||||
if (MSVC)
|
||||
# warning level 4 and all warnings as errors
|
||||
add_compile_options(/W4 /WX)
|
||||
else()
|
||||
# lots of warnings and all warnings as errors
|
||||
add_compile_options(-Wall -Wextra -pedantic -Werror)
|
||||
endif()
|
||||
|
||||
add_executable(${CMAKE_PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}/${CURRENT_PROJECT_CODE_NAME}.${FILE_EXT})
|
||||
|
||||
target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC
|
||||
${EXTRA_INCLUDES}
|
||||
)
|
||||
|
||||
target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC
|
||||
${EXTRA_LIBS}
|
||||
)
|
||||
|
||||
|
||||
24
Endian/C/endian.c
Normal file
24
Endian/C/endian.c
Normal file
@@ -0,0 +1,24 @@
|
||||
#include <stdio.h>
|
||||
|
||||
void show_memory(const char* begin, size_t length)
|
||||
{
|
||||
size_t i = 0;
|
||||
for (; i < length; i++)
|
||||
{
|
||||
printf(" %.2x", 0xff & begin[i]); // 0xff is necessary due to type promotion
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
float f = 42654.2312f;
|
||||
int i = 7753238;
|
||||
printf("Printing float %f with size %ld\n", f, sizeof(f));
|
||||
show_memory((char*)&f, sizeof(f));
|
||||
printf("Printing int %d with size %ld\n", i, sizeof(f));
|
||||
show_memory((char*)&i, sizeof(i));
|
||||
return 0;
|
||||
}
|
||||
4
Endian/CMakeLists.txt
Normal file
4
Endian/CMakeLists.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/C/CMakeLists.txt)
|
||||
#include(${CMAKE_CURRENT_LIST_DIR}/Cpp/CMakeLists.txt)
|
||||
Reference in New Issue
Block a user