Skip to content

Commit 066e0e0

Browse files
committed
Enums and unions
1 parent 7c30bff commit 066e0e0

File tree

5 files changed

+260
-0
lines changed

5 files changed

+260
-0
lines changed
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<VCProjectVersion>16.0</VCProjectVersion>
23+
<Keyword>Win32Proj</Keyword>
24+
<ProjectGuid>{40bbbc29-ba0f-4c03-9dec-da3f1a65e1f5}</ProjectGuid>
25+
<RootNamespace>My06AdvancedCStructs</RootNamespace>
26+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
27+
</PropertyGroup>
28+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
29+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
30+
<ConfigurationType>Application</ConfigurationType>
31+
<UseDebugLibraries>true</UseDebugLibraries>
32+
<PlatformToolset>v143</PlatformToolset>
33+
<CharacterSet>Unicode</CharacterSet>
34+
</PropertyGroup>
35+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
36+
<ConfigurationType>Application</ConfigurationType>
37+
<UseDebugLibraries>false</UseDebugLibraries>
38+
<PlatformToolset>v143</PlatformToolset>
39+
<WholeProgramOptimization>true</WholeProgramOptimization>
40+
<CharacterSet>Unicode</CharacterSet>
41+
</PropertyGroup>
42+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
43+
<ConfigurationType>Application</ConfigurationType>
44+
<UseDebugLibraries>true</UseDebugLibraries>
45+
<PlatformToolset>v143</PlatformToolset>
46+
<CharacterSet>Unicode</CharacterSet>
47+
</PropertyGroup>
48+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
49+
<ConfigurationType>Application</ConfigurationType>
50+
<UseDebugLibraries>false</UseDebugLibraries>
51+
<PlatformToolset>v143</PlatformToolset>
52+
<WholeProgramOptimization>true</WholeProgramOptimization>
53+
<CharacterSet>Unicode</CharacterSet>
54+
</PropertyGroup>
55+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
56+
<ImportGroup Label="ExtensionSettings">
57+
</ImportGroup>
58+
<ImportGroup Label="Shared">
59+
</ImportGroup>
60+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
61+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
62+
</ImportGroup>
63+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
64+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
65+
</ImportGroup>
66+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
67+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
68+
</ImportGroup>
69+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
70+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
71+
</ImportGroup>
72+
<PropertyGroup Label="UserMacros" />
73+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
74+
<TargetName>AdvancedCStructs</TargetName>
75+
<OutDir>$(SolutionDir)build\bin\$(PlatformShortName)-$(Configuration)\</OutDir>
76+
<IntDir>$(SolutionDir)build\obj\$(PlatformShortName)-$(Configuration)\$(ProjectName)\</IntDir>
77+
</PropertyGroup>
78+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
79+
<TargetName>AdvancedCStructs</TargetName>
80+
<OutDir>$(SolutionDir)build\bin\$(PlatformShortName)-$(Configuration)\</OutDir>
81+
<IntDir>$(SolutionDir)build\obj\$(PlatformShortName)-$(Configuration)\$(ProjectName)\</IntDir>
82+
</PropertyGroup>
83+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
84+
<TargetName>AdvancedCStructs</TargetName>
85+
<OutDir>$(SolutionDir)build\bin\$(PlatformShortName)-$(Configuration)\</OutDir>
86+
<IntDir>$(SolutionDir)build\obj\$(PlatformShortName)-$(Configuration)\$(ProjectName)\</IntDir>
87+
</PropertyGroup>
88+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
89+
<TargetName>AdvancedCStructs</TargetName>
90+
<OutDir>$(SolutionDir)build\bin\$(PlatformShortName)-$(Configuration)\</OutDir>
91+
<IntDir>$(SolutionDir)build\obj\$(PlatformShortName)-$(Configuration)\$(ProjectName)\</IntDir>
92+
</PropertyGroup>
93+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
94+
<ClCompile>
95+
<WarningLevel>Level3</WarningLevel>
96+
<SDLCheck>true</SDLCheck>
97+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
98+
<ConformanceMode>true</ConformanceMode>
99+
</ClCompile>
100+
<Link>
101+
<SubSystem>Console</SubSystem>
102+
<GenerateDebugInformation>true</GenerateDebugInformation>
103+
</Link>
104+
</ItemDefinitionGroup>
105+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
106+
<ClCompile>
107+
<WarningLevel>Level3</WarningLevel>
108+
<FunctionLevelLinking>true</FunctionLevelLinking>
109+
<IntrinsicFunctions>true</IntrinsicFunctions>
110+
<SDLCheck>true</SDLCheck>
111+
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
112+
<ConformanceMode>true</ConformanceMode>
113+
</ClCompile>
114+
<Link>
115+
<SubSystem>Console</SubSystem>
116+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
117+
<OptimizeReferences>true</OptimizeReferences>
118+
<GenerateDebugInformation>true</GenerateDebugInformation>
119+
</Link>
120+
</ItemDefinitionGroup>
121+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
122+
<ClCompile>
123+
<WarningLevel>Level3</WarningLevel>
124+
<SDLCheck>true</SDLCheck>
125+
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
126+
<ConformanceMode>true</ConformanceMode>
127+
</ClCompile>
128+
<Link>
129+
<SubSystem>Console</SubSystem>
130+
<GenerateDebugInformation>true</GenerateDebugInformation>
131+
</Link>
132+
</ItemDefinitionGroup>
133+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
134+
<ClCompile>
135+
<WarningLevel>Level3</WarningLevel>
136+
<FunctionLevelLinking>true</FunctionLevelLinking>
137+
<IntrinsicFunctions>true</IntrinsicFunctions>
138+
<SDLCheck>true</SDLCheck>
139+
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
140+
<ConformanceMode>true</ConformanceMode>
141+
</ClCompile>
142+
<Link>
143+
<SubSystem>Console</SubSystem>
144+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
145+
<OptimizeReferences>true</OptimizeReferences>
146+
<GenerateDebugInformation>true</GenerateDebugInformation>
147+
</Link>
148+
</ItemDefinitionGroup>
149+
<ItemGroup>
150+
<ClCompile Include="main.c" />
151+
</ItemGroup>
152+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
153+
<ImportGroup Label="ExtensionTargets">
154+
</ImportGroup>
155+
</Project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="Source Files">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="Header Files">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="Resource Files">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ClCompile Include="main.c">
19+
<Filter>Source Files</Filter>
20+
</ClCompile>
21+
</ItemGroup>
22+
</Project>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<ShowAllFiles>true</ShowAllFiles>
5+
</PropertyGroup>
6+
</Project>

06_AdvancedCStructs/main.c

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
4+
typedef enum
5+
{
6+
CordinateDimension2D = 2,
7+
CordinateDimension3D = 3,
8+
} CordinateDimension;
9+
10+
typedef struct
11+
{
12+
CordinateDimension dimension;
13+
14+
union
15+
{
16+
struct
17+
{
18+
int x;
19+
int y;
20+
int z;
21+
} d3;
22+
23+
struct
24+
{
25+
int x;
26+
int y;
27+
} d2;
28+
};
29+
} Cordinate;
30+
31+
Cordinate MakeCordinate2D(int x, int y)
32+
{
33+
Cordinate c;
34+
c.dimension = CordinateDimension2D;
35+
c.d2.x = x;
36+
c.d2.y = y;
37+
return c;
38+
}
39+
40+
Cordinate MakeCordinate3D(int x, int y, int z)
41+
{
42+
Cordinate c;
43+
c.dimension = CordinateDimension3D;
44+
c.d3.x = x;
45+
c.d3.y = y;
46+
c.d3.z = z;
47+
return c;
48+
}
49+
50+
void DoWork(Cordinate c)
51+
{
52+
printf_s("Coridate with a order of %i\n", c.dimension);
53+
if (c.dimension == CordinateDimension2D)
54+
{
55+
printf_s("Coridate 2D: x: %i y: %i\n", c.d2.x, c.d2.y);
56+
}
57+
else if (c.dimension == CordinateDimension3D)
58+
{
59+
printf_s("Coridate 3D: x: %i y: %i z: %i\n", c.d3.x, c.d3.y, c.d3.z);
60+
}
61+
}
62+
63+
int main()
64+
{
65+
DoWork(MakeCordinate2D(5, 5));
66+
DoWork(MakeCordinate3D(5, 5, -5));
67+
}

C-Cpp-Tutorial.sln

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "05_INIExplorer", "05_INIExp
2020
{919D474A-6558-42AB-83A7-35BA94D3A66C} = {919D474A-6558-42AB-83A7-35BA94D3A66C}
2121
EndProjectSection
2222
EndProject
23+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "06_AdvancedCStructs", "06_AdvancedCStructs\06_AdvancedCStructs.vcxproj", "{40BBBC29-BA0F-4C03-9DEC-DA3F1A65E1F5}"
24+
EndProject
2325
Global
2426
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2527
Debug|x64 = Debug|x64
@@ -76,6 +78,14 @@ Global
7678
{1EC0F4F2-3FE1-4829-9469-657981FCFED0}.Release|x64.Build.0 = Release|x64
7779
{1EC0F4F2-3FE1-4829-9469-657981FCFED0}.Release|x86.ActiveCfg = Release|Win32
7880
{1EC0F4F2-3FE1-4829-9469-657981FCFED0}.Release|x86.Build.0 = Release|Win32
81+
{40BBBC29-BA0F-4C03-9DEC-DA3F1A65E1F5}.Debug|x64.ActiveCfg = Debug|x64
82+
{40BBBC29-BA0F-4C03-9DEC-DA3F1A65E1F5}.Debug|x64.Build.0 = Debug|x64
83+
{40BBBC29-BA0F-4C03-9DEC-DA3F1A65E1F5}.Debug|x86.ActiveCfg = Debug|Win32
84+
{40BBBC29-BA0F-4C03-9DEC-DA3F1A65E1F5}.Debug|x86.Build.0 = Debug|Win32
85+
{40BBBC29-BA0F-4C03-9DEC-DA3F1A65E1F5}.Release|x64.ActiveCfg = Release|x64
86+
{40BBBC29-BA0F-4C03-9DEC-DA3F1A65E1F5}.Release|x64.Build.0 = Release|x64
87+
{40BBBC29-BA0F-4C03-9DEC-DA3F1A65E1F5}.Release|x86.ActiveCfg = Release|Win32
88+
{40BBBC29-BA0F-4C03-9DEC-DA3F1A65E1F5}.Release|x86.Build.0 = Release|Win32
7989
EndGlobalSection
8090
GlobalSection(SolutionProperties) = preSolution
8191
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)