Skip to main content
added 503 characters in body
Source Link
chux
  • 36.4k
  • 2
  • 43
  • 96

I learned to use space for programming instead of tab, and we were told to do 3 spaces, how many space do you recommend 2, 3, 4, or X amount?
And how many space do you use when programming?

This is a style issue and best to follow your group's coding standard which apparently is 3. I use 2.

A good coding environment allows you to change the indent on the entire file quickly with a set-up option and invoking that auto formatter.

If you are manually editing for the correct indentation, you are inefficient. Use an auto-formatter.


Deceleration ....

Whoa, slow down there 😉. Did you mean Declaration?


Namespace

Rather than

struct Node{
int32_t split_list()
int32_t merge_sort()
void print_list()
int32_t push_list()
void free_list()

Consider a uniform naming

struct DList {
int32_t DList_split()
int32_t DList_merge_sort()
void DList_print()
int32_t DList_push()
void DList_free()

Form a DList.h header file and segregate your DList functions into a DList.c file.

Weak compare

*(int *)(node1->data) - *(int *)(node2->data) risks UB and an incorrect result when the subtraction incurs overflow.

Instead:

int i1 = *(int *)(node1->data);
int i2 = *(int *)(node2->data);
return (i1 > i2) - (i1 < i2);

int vs. int32_t vs ....

I see little value is using int32_t here. Recommend reworking code to size_t for a type that relates to array indexing and int/bool for a simple success flag.

Minor: () not needed

Style issue:

// node = malloc(sizeof(*node));
node = malloc(sizeof *node);

I learned to use space for programming instead of tab, and we were told to do 3 spaces, how many space do you recommend 2, 3, 4, or X amount?

This is a style issue and best to follow your group's coding standard which apparently is 3. I use 2.

A good coding environment allows you to change the indent on the entire file quickly with a set-up option and invoking that auto formatter.

If you are manually editing for the correct indentation, you are inefficient. Use an auto-formatter.


Deceleration ....

Whoa, slow down there 😉. Did you mean Declaration?


Namespace

Rather than

struct Node{
int32_t split_list()
int32_t merge_sort()
void print_list()
int32_t push_list()
void free_list()

Consider a uniform naming

struct DList {
int32_t DList_split()
int32_t DList_merge_sort()
void DList_print()
int32_t DList_push()
void DList_free()

Form a DList.h header file and segregate your DList functions into a DList.c file.

Weak compare

*(int *)(node1->data) - *(int *)(node2->data) risks UB and an incorrect result when the subtraction incurs overflow.

Instead:

int i1 = *(int *)(node1->data);
int i2 = *(int *)(node2->data);
return (i1 > i2) - (i1 < i2);

Minor: () not needed

Style issue:

// node = malloc(sizeof(*node));
node = malloc(sizeof *node);

I learned to use space for programming instead of tab, and we were told to do 3 spaces, how many space do you recommend 2, 3, 4, or X amount?
And how many space do you use when programming?

This is a style issue and best to follow your group's coding standard which apparently is 3. I use 2.

A good coding environment allows you to change the indent on the entire file quickly with a set-up option and invoking that auto formatter.

If you are manually editing for the correct indentation, you are inefficient. Use an auto-formatter.


Deceleration ....

Whoa, slow down there 😉. Did you mean Declaration?


Namespace

Rather than

struct Node{
int32_t split_list()
int32_t merge_sort()
void print_list()
int32_t push_list()
void free_list()

Consider a uniform naming

struct DList {
int32_t DList_split()
int32_t DList_merge_sort()
void DList_print()
int32_t DList_push()
void DList_free()

Form a DList.h header file and segregate your DList functions into a DList.c file.

Weak compare

*(int *)(node1->data) - *(int *)(node2->data) risks UB and an incorrect result when the subtraction incurs overflow.

Instead:

int i1 = *(int *)(node1->data);
int i2 = *(int *)(node2->data);
return (i1 > i2) - (i1 < i2);

int vs. int32_t vs ....

I see little value is using int32_t here. Recommend reworking code to size_t for a type that relates to array indexing and int/bool for a simple success flag.

Minor: () not needed

Style issue:

// node = malloc(sizeof(*node));
node = malloc(sizeof *node);
added 503 characters in body
Source Link
chux
  • 36.4k
  • 2
  • 43
  • 96

I learned to use space for programming instead of tab, and we were told to do 3 spaces, how many space do you recommend 2, 3, 4, or X amount?

This is a style issue and best to follow your group's coding standard which apparently is 3. I use 2.

A good coding environment allows you to change the indent on the entire file quickly with a set-up option and invoking that auto formatter.

If you are manually editing for the correct indentation, you are inefficient. Use an auto-formatter.


Deceleration ....

Whoa, slow down there 😉. Did you mean Declaration?


Namespace

Rather than

struct Node{
int32_t split_list()
int32_t merge_sort()
void print_list()
int32_t push_list()
void free_list()

Consider a uniform naming

struct DList {
int32_t DList_split()
int32_t DList_merge_sort()
void DList_print()
int32_t DList_push()
void DList_free()

Form a DList.h header file and segregate your DList functions into a `DList.cDList.c file.

Weak compare

*(int *)(node1->data) - *(int *)(node2->data) risks UB and an incorrect result when the subtraction incurs overflow.

Instead:

int i1 = *(int *)(node1->data);
int i2 = *(int *)(node2->data);
return return (i1 > i2) - (i1 < i2);

Minor: () not needed

Style issue:

// node = malloc(sizeof(*node));
node = malloc(sizeof *node);

Namespace

Rather than

struct Node{
int32_t split_list()
int32_t merge_sort()
void print_list()
int32_t push_list()
void free_list()

Consider a uniform naming

struct DList {
int32_t DList_split()
int32_t DList_merge_sort()
void DList_print()
int32_t DList_push()
void DList_free()

Form a DList.h header file and segregate your DList functions into a `DList.c file.

Weak compare

*(int *)(node1->data) - *(int *)(node2->data) risks UB and an incorrect result when the subtraction incurs overflow.

Instead:

int i1 = *(int *)(node1->data);
int i2 = *(int *)(node2->data);
return return (i1 > i2) - (i1 < i2);

Minor: () not needed

Style issue:

// node = malloc(sizeof(*node));
node = malloc(sizeof *node);

I learned to use space for programming instead of tab, and we were told to do 3 spaces, how many space do you recommend 2, 3, 4, or X amount?

This is a style issue and best to follow your group's coding standard which apparently is 3. I use 2.

A good coding environment allows you to change the indent on the entire file quickly with a set-up option and invoking that auto formatter.

If you are manually editing for the correct indentation, you are inefficient. Use an auto-formatter.


Deceleration ....

Whoa, slow down there 😉. Did you mean Declaration?


Namespace

Rather than

struct Node{
int32_t split_list()
int32_t merge_sort()
void print_list()
int32_t push_list()
void free_list()

Consider a uniform naming

struct DList {
int32_t DList_split()
int32_t DList_merge_sort()
void DList_print()
int32_t DList_push()
void DList_free()

Form a DList.h header file and segregate your DList functions into a DList.c file.

Weak compare

*(int *)(node1->data) - *(int *)(node2->data) risks UB and an incorrect result when the subtraction incurs overflow.

Instead:

int i1 = *(int *)(node1->data);
int i2 = *(int *)(node2->data);
return (i1 > i2) - (i1 < i2);

Minor: () not needed

Style issue:

// node = malloc(sizeof(*node));
node = malloc(sizeof *node);
Source Link
chux
  • 36.4k
  • 2
  • 43
  • 96

Namespace

Rather than

struct Node{
int32_t split_list()
int32_t merge_sort()
void print_list()
int32_t push_list()
void free_list()

Consider a uniform naming

struct DList {
int32_t DList_split()
int32_t DList_merge_sort()
void DList_print()
int32_t DList_push()
void DList_free()

Form a DList.h header file and segregate your DList functions into a `DList.c file.

Weak compare

*(int *)(node1->data) - *(int *)(node2->data) risks UB and an incorrect result when the subtraction incurs overflow.

Instead:

int i1 = *(int *)(node1->data);
int i2 = *(int *)(node2->data);
return return (i1 > i2) - (i1 < i2);

Minor: () not needed

Style issue:

// node = malloc(sizeof(*node));
node = malloc(sizeof *node);