diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1ff0c42 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1bc915c --- /dev/null +++ b/.gitignore @@ -0,0 +1,156 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results + +[Dd]ebug/ +[Rr]elease/ +x64/ +build/ +[Bb]in/ +[Oo]bj/ + +# Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets +!packages/*/build/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +*_i.c +*_p.c +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.log +*.scc + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +*.ncrunch* +.*crunch*.local.xml + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.Publish.xml + +# NuGet Packages Directory +## TODO: If you have NuGet Package Restore enabled, uncomment the next line +#packages/ + +# Windows Azure Build Output +csx +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +sql/ +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.[Pp]ublish.xml +*.pfx +*.publishsettings + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file to a newer +# Visual Studio version. Backup files are not needed, because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +App_Data/*.mdf +App_Data/*.ldf + + +#LightSwitch generated files +GeneratedArtifacts/ +_Pvt_Extensions/ +ModelManifest.xml + +# ========================= +# Windows detritus +# ========================= + +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Mac desktop service store files +.DS_Store diff --git a/dynarrc.sln b/dynarrc.sln new file mode 100644 index 0000000..0bdfead --- /dev/null +++ b/dynarrc.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Express 2013 for Windows Desktop +VisualStudioVersion = 12.0.30723.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dynarrc", "dynarrc\dynarrc.vcxproj", "{12F7EC17-45E8-4C4E-880C-2ABA46A79BCF}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {12F7EC17-45E8-4C4E-880C-2ABA46A79BCF}.Debug|Win32.ActiveCfg = Debug|Win32 + {12F7EC17-45E8-4C4E-880C-2ABA46A79BCF}.Debug|Win32.Build.0 = Debug|Win32 + {12F7EC17-45E8-4C4E-880C-2ABA46A79BCF}.Release|Win32.ActiveCfg = Release|Win32 + {12F7EC17-45E8-4C4E-880C-2ABA46A79BCF}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/dynarrc/common.h b/dynarrc/common.h new file mode 100644 index 0000000..7bd9c6e --- /dev/null +++ b/dynarrc/common.h @@ -0,0 +1,54 @@ +#ifndef __dynarr_common_h__ +#define __dynarr_common_h__ + +/* for token-pasting and string concatenation */ +#define MACRO_EVAL2(x) (x) +#define MACRO_EVAL(x) MACRO_EVAL2(x) + + +#define _TOKEN_PASTE(x,y) x ## y +#define TOKEN_PASTE(x,y) _TOKEN_PASTE(x,y) + +#define TO_STRING(x) TO_STRING2(x) +#define TO_STRING2(x) #x + +// memory leak detection +#define DETECT_MEM_LEAK 1 +// http://msdn.microsoft.com/en-us/library/e5ewb1h3(v=vs.90).aspx +#if DETECT_MEM_LEAK +#define _CRTDBG_MAP_ALLOC +#include +#include +#define MEM_LEAK_CATCH() \ + (_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF )) +#define MEM_LEAK_SHOW() _CrtDumpMemoryLeaks() + +#else // DETECT_MEM_LEAK +#define MEM_LEAK_CATCH() +#define MEM_LEAK_SHOW() +#endif // DETECT_MEM_LEAK + +/* Simple macros*/ +// success and failure +#define SUCCESS 0 +#define FAILURE -1 +// off and on +#define OFF 0 +#define ON 1 +// param purpose specifier +#define PARAM_OUT +#define PARAM_IN + +// free mem and set NULL +#define FREE_SAFE(x) \ + ( (x) ? ( free( (x) ) , (x) = NULL ) : (void) 0 ) +#define DELETE_SAFE(x) \ + ( (x) ? ( delete (x) , (x) = NULL ) : (void) 0 ) +#define DELETE_SAFE_ARR(x) \ + ( (x) ? ( delete[] (x) , (x) = NULL ) : (void) 0 ) + +// size of array +#define SIZE_ARR(a) ( ((a)!=NULL) ? sizeof(a) / sizeof((a)[0]) : 0) + + +#endif // __dynarr_common_h__ \ No newline at end of file diff --git a/dynarrc/dynarr.c b/dynarrc/dynarr.c new file mode 100644 index 0000000..06ac2cb --- /dev/null +++ b/dynarrc/dynarr.c @@ -0,0 +1,33 @@ +#include "common.h" +#include +#include + +#define MAXSEG 5 +#define DYNARR_TYPE int +#define TYPED_NAME( name ) TOKEN_PASTE(DYNARR_TYPE, name) +#include "dynarr.h" +typedef struct TYPED_NAME(DynArr) IdArr; + + +#define DYNARR_TYPE float +#define TYPED_NAME( name ) TOKEN_PASTE(DYNARR_TYPE, name) +#include "dynarr.h" +typedef struct TYPED_NAME(DynArr) ValueArr; + + +int main(int argc, char** argv){ + MEM_LEAK_CATCH(); + + IdArr *p1; + ValueArr *p2; + + p1 = (IdArr*)malloc(sizeof(IdArr)); + p2 = (ValueArr*)malloc(sizeof(ValueArr)); + + + // done + FREE_SAFE(p1); + FREE_SAFE(p2); + MEM_LEAK_SHOW(); + return 0; +} \ No newline at end of file diff --git a/dynarrc/dynarr.h b/dynarrc/dynarr.h new file mode 100644 index 0000000..7d214d3 --- /dev/null +++ b/dynarrc/dynarr.h @@ -0,0 +1,32 @@ +#pragma message("touching: "__FILE__) +#include "common.h" + +/* Assuming MAXSEG is defined. + Size of each block of the dynamic array. + Must be a positive integer.*/ +/* Assuming DYNARR_TYPE is defined. + The data type of the array. + Must be a valid one-word type without space, *, etc. (use typedef if necessary) + */ +#ifndef MAXSEG +#pragma message("MAXSEG must be defined before including " __FILE__) +#elif MAXSEG <= 0 +#pragma message("MAXSEG has non positive value: " MAXSEG) +#elif !defined(DYNARR_TYPE) +#pragma message("DYNARR_TYPE must be defined before including " __FILE__) +#else +// everything is fine + +// prefixing + +/* The dynamic array data structure */ +struct TYPED_NAME(DynArr){ + int a; +}; + + +#endif + + + + diff --git a/dynarrc/dynarrc.vcxproj b/dynarrc/dynarrc.vcxproj new file mode 100644 index 0000000..798b95a --- /dev/null +++ b/dynarrc/dynarrc.vcxproj @@ -0,0 +1,76 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {12F7EC17-45E8-4C4E-880C-2ABA46A79BCF} + dynarrc + + + + Application + true + v120 + MultiByte + + + Application + false + v120 + true + MultiByte + + + + + + + + + + + + + + + Level3 + Disabled + true + + + true + + + + + Level3 + MaxSpeed + true + true + true + + + true + true + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/dynarrc/dynarrc.vcxproj.filters b/dynarrc/dynarrc.vcxproj.filters new file mode 100644 index 0000000..54c1bed --- /dev/null +++ b/dynarrc/dynarrc.vcxproj.filters @@ -0,0 +1,30 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Header Files + + + Header Files + + + + + Source Files + + + \ No newline at end of file