Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Word Size
The size of unsigned int is compiler/machine dependent, the typedef name ak_u32 is misleading, see this StackOverflow question StackOverflow question. This can lead to portability problems and your alignment isn't guarenteed.

Word Size
The size of unsigned int is compiler/machine dependent, the typedef name ak_u32 is misleading, see this StackOverflow question. This can lead to portability problems and your alignment isn't guarenteed.

Word Size
The size of unsigned int is compiler/machine dependent, the typedef name ak_u32 is misleading, see this StackOverflow question. This can lead to portability problems and your alignment isn't guarenteed.

Added a missing line to clarify code. Corrected grammar.
Source Link
pacmaninbw
  • 26.2k
  • 13
  • 47
  • 113

Using your initials isn't a bad idea, but I would use ak__ rather than ak_ as the prefix. That way it's clearer that it is a prefix rather than an abbreviation. It's obvious that you're trying to work around the fact that the C language doesn't support name spaces.

#define ak_slab_link(slab, fwd, back) 
 do { 
 ak_slab* const sL = (slab); 
 ak_slab* const fL = (fwd); 
 ak_slab* const bL = (back); 
 ak_slab_link_bk(sL, bL); 
 do { 
 ak_slab* const sLB = (slab); 
 ak_slab* const bLB = (back); 
 sLB->bk = bLB; 
 bLB->fd = sLB; 
 } while (0);
 do { 
 ak_slab* const sLF = (slab); 
 ak_slab* const fLF = (fwd); 
 sLF->fd = fLF; 
 fLF->bk = sLF; 
 } while (0);
 } while (0)

When it could simply be:

 sLB->bk = (slab);
 bLB->fd = (back); 
 sLF->fd = (fwd); 
 fLF->bk = (slab);

Using your initials isn't a bad idea, but I would use ak__ rather than ak_ as the prefix. That way it's clearer that a prefix rather than an abbreviation. It's obvious that you're trying to work around the fact that the C language doesn't support name spaces.

#define ak_slab_link(slab, fwd, back) 
 do { 
 ak_slab* const sL = (slab); 
 ak_slab* const fL = (fwd); 
 ak_slab* const bL = (back); 
 ak_slab_link_bk(sL, bL); 
 do { 
 ak_slab* const sLB = (slab); 
 ak_slab* const bLB = (back); 
 sLB->bk = bLB; 
 bLB->fd = sLB; 
 } while (0);
 do { 
 ak_slab* const sLF = (slab); 
 ak_slab* const fLF = (fwd); 
 sLF->fd = fLF; 
 fLF->bk = sLF; 
 } while (0);
 } while (0)
 sLB->bk = (slab);
 bLB->fd = (back); 
 sLF->fd = (fwd); 
 fLF->bk = (slab);

Using your initials isn't a bad idea, but I would use ak__ rather than ak_ as the prefix. That way it's clearer that it is a prefix rather than an abbreviation. It's obvious that you're trying to work around the fact that the C language doesn't support name spaces.

#define ak_slab_link(slab, fwd, back) 
 do { 
 ak_slab* const sL = (slab); 
 ak_slab* const fL = (fwd); 
 ak_slab* const bL = (back); 
 ak_slab_link_bk(sL, bL); 
 do { 
 ak_slab* const sLB = (slab); 
 ak_slab* const bLB = (back); 
 sLB->bk = bLB; 
 bLB->fd = sLB; 
 } while (0);
 do { 
 ak_slab* const sLF = (slab); 
 ak_slab* const fLF = (fwd); 
 sLF->fd = fLF; 
 fLF->bk = sLF; 
 } while (0);
 } while (0)

When it could simply be:

 sLB->bk = (slab);
 bLB->fd = (back); 
 sLF->fd = (fwd); 
 fLF->bk = (slab);
added 4 characters in body
Source Link
syb0rg
  • 21.9k
  • 10
  • 113
  • 192

NULLPTR
As a C programmer I know what NULL is. If I wanted to define my own NULL I would probably do it this way
#define AK_NULLPTR NULL

#define AK_NULLPTR NULL

is the following:
#define ak_slab_link(slab, fwd, back)
do {
ak_slab* const sL = (slab);
ak_slab* const fL = (fwd);
ak_slab* const bL = (back);
ak_slab_link_bk(sL, bL);
do {
ak_slab* const sLB = (slab);
ak_slab* const bLB = (back);
sLB->bk = bLB;
bLB->fd = sLB;
} while (0); do {
ak_slab* const sLF = (slab);
ak_slab* const fLF = (fwd);
sLF->fd = fLF;
fLF->bk = sLF;
} while (0); } while (0)

#define ak_slab_link(slab, fwd, back) 
 do { 
 ak_slab* const sL = (slab); 
 ak_slab* const fL = (fwd); 
 ak_slab* const bL = (back); 
 ak_slab_link_bk(sL, bL); 
 do {  
 ak_slab* const sLB = (slab); 
 ak_slab* const bLB = (back); 
 sLB->bk = bLB; 
  bLB->fd = sLB; 
 } while (0);
 do { 
 ak_slab* const sLF = (slab); 
 ak_slab* const fLF = (fwd); 
 sLF->fd = fLF; 
 fLF->bk = sLF; 
 } while (0);
 } while (0)
 sLB->bk = (slab);
 bLB->fd = (back); 
 sLF->fd = (fwd); 
 fLF->bk = (slab);

If I needed to maintain ak_slab_link()ak_slab_link() with the current implementation it is quite confusing.

NULLPTR
As a C programmer I know what NULL is. If I wanted to define my own NULL I would probably do it this way
#define AK_NULLPTR NULL

is the following:
#define ak_slab_link(slab, fwd, back)
do {
ak_slab* const sL = (slab);
ak_slab* const fL = (fwd);
ak_slab* const bL = (back);
ak_slab_link_bk(sL, bL);
do {
ak_slab* const sLB = (slab);
ak_slab* const bLB = (back);
sLB->bk = bLB;
bLB->fd = sLB;
} while (0); do {
ak_slab* const sLF = (slab);
ak_slab* const fLF = (fwd);
sLF->fd = fLF;
fLF->bk = sLF;
} while (0); } while (0)

 sLB->bk = (slab);
 bLB->fd = (back); 
 sLF->fd = (fwd); 
 fLF->bk = (slab);

If I needed to maintain ak_slab_link() with the current implementation it is quite confusing.

NULLPTR
As a C programmer I know what NULL is. If I wanted to define my own NULL I would probably do it this way

#define AK_NULLPTR NULL

is the following:

#define ak_slab_link(slab, fwd, back) 
 do { 
 ak_slab* const sL = (slab); 
 ak_slab* const fL = (fwd); 
 ak_slab* const bL = (back); 
 ak_slab_link_bk(sL, bL); 
 do {  
 ak_slab* const sLB = (slab); 
 ak_slab* const bLB = (back); 
 sLB->bk = bLB; 
  bLB->fd = sLB; 
 } while (0);
 do { 
 ak_slab* const sLF = (slab); 
 ak_slab* const fLF = (fwd); 
 sLF->fd = fLF; 
 fLF->bk = sLF; 
 } while (0);
 } while (0)
 sLB->bk = (slab);
 bLB->fd = (back); 
 sLF->fd = (fwd); 
 fLF->bk = (slab);

If I needed to maintain ak_slab_link() with the current implementation it is quite confusing.

Source Link
pacmaninbw
  • 26.2k
  • 13
  • 47
  • 113
Loading
lang-c

AltStyle によって変換されたページ (->オリジナル) /