Skip to main content
added 618 characters in body
Source Link
chux
  • 36.5k
  • 2
  • 43
  • 97

OnlyVery Nice.
Only small stuff

1 Why (float) in size_t new_slots = (float)stack->slots * stack->multiplier;?

  1. Given sizeof size_t may not equal sizeof float, suggest grouping like types in struct

     typedef struct {
         void *content;
         size_t element_size;
         ...
         size_t expansion_amount;
         float multiplier;
     } Stack;
    
  2. Since new_stack() may return NULL, note the other main functions are not protected from dereferencing NULL. Protection is not a hard requirement here - more about design philosophy about should main level routine have NULL protection? Your call.

  1. Why (float) in size_t new_slots = (float)stack->slots * stack->multiplier;?

  2. Given sizeof size_t may not equal sizeof float, suggest grouping like types in struct

     typedef struct {
         void *content;
         size_t element_size;
         ...
         size_t expansion_amount;
         float multiplier;
     } Stack;
    
  3. Since new_stack() may return NULL, note the other main functions are not protected from dereferencing NULL. Protection is not a hard requirement here - more about design philosophy about should main level routine have NULL protection? Your call.

  4. Minor: Could use a float in the define to emphasize the value will be used as a float.
    #define MULTIPLIER (1.00f)

  5. (I assume your header is at global scope.) Since typedef struct { ... } Stack is only used by an application as a pointer, could use an anonymous pointer to insure information hiding.

  6. The defines may be useful to an application as defaults parameters. There, they could appear at global scope, so use less generic names.

     #define Stack_MINIMUM_ELEMENT_SIZE (1)
     #define Stack_MULTIPLIER (1.0f)
     #define Stack_EXPANSION_AMOUNT (8)
    

Only small stuff

1 Why (float) in size_t new_slots = (float)stack->slots * stack->multiplier;?

  1. Given sizeof size_t may not equal sizeof float, suggest grouping like types in struct

     typedef struct {
         void *content;
         size_t element_size;
         ...
         size_t expansion_amount;
         float multiplier;
     } Stack;
    
  2. Since new_stack() may return NULL, note the other main functions are not protected from dereferencing NULL. Protection is not a hard requirement here - more about design philosophy about should main level routine have NULL protection? Your call.

Very Nice.
Only small stuff

  1. Why (float) in size_t new_slots = (float)stack->slots * stack->multiplier;?

  2. Given sizeof size_t may not equal sizeof float, suggest grouping like types in struct

     typedef struct {
         void *content;
         size_t element_size;
         ...
         size_t expansion_amount;
         float multiplier;
     } Stack;
    
  3. Since new_stack() may return NULL, note the other main functions are not protected from dereferencing NULL. Protection is not a hard requirement here - more about design philosophy about should main level routine have NULL protection? Your call.

  4. Minor: Could use a float in the define to emphasize the value will be used as a float.
    #define MULTIPLIER (1.00f)

  5. (I assume your header is at global scope.) Since typedef struct { ... } Stack is only used by an application as a pointer, could use an anonymous pointer to insure information hiding.

  6. The defines may be useful to an application as defaults parameters. There, they could appear at global scope, so use less generic names.

     #define Stack_MINIMUM_ELEMENT_SIZE (1)
     #define Stack_MULTIPLIER (1.0f)
     #define Stack_EXPANSION_AMOUNT (8)
    
Source Link
chux
  • 36.5k
  • 2
  • 43
  • 97

Only small stuff

1 Why (float) in size_t new_slots = (float)stack->slots * stack->multiplier;?

  1. Given sizeof size_t may not equal sizeof float, suggest grouping like types in struct

     typedef struct {
         void *content;
         size_t element_size;
         ...
         size_t expansion_amount;
         float multiplier;
     } Stack;
    
  2. Since new_stack() may return NULL, note the other main functions are not protected from dereferencing NULL. Protection is not a hard requirement here - more about design philosophy about should main level routine have NULL protection? Your call.