Skip to content
Permalink
Browse files

Intial commit. The struct and the typed-names work.

Memory leak included.

Signed-off-by: saad0105050 <saad0105050@gmail.com>
  • Loading branch information...
saad0105050
saad0105050 committed Oct 1, 2014
0 parents commit ec27b6b1231b599d1dffc5cf3f25e74467f756f3
Showing with 466 additions and 0 deletions.
  1. +63 −0 .gitattributes
  2. +156 −0 .gitignore
  3. +22 −0 dynarrc.sln
  4. +54 −0 dynarrc/common.h
  5. +33 −0 dynarrc/dynarr.c
  6. +32 −0 dynarrc/dynarr.h
  7. +76 −0 dynarrc/dynarrc.vcxproj
  8. +30 −0 dynarrc/dynarrc.vcxproj.filters
@@ -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
@@ -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
@@ -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
@@ -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 <stdlib.h>
#include <crtdbg.h>
#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__
@@ -0,0 +1,33 @@
#include "common.h"
#include <stdio.h>
#include <stdlib.h>

#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;
}
@@ -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




Oops, something went wrong.

0 comments on commit ec27b6b

Please sign in to comment.
You can’t perform that action at this time.