Skip to main content
added 22 characters in body
Source Link
chux
  • 36.5k
  • 2
  • 43
  • 97
... const int xsize,const int ysize ...
for(long long int i = 0; i <(xsize * ysize); i++) // Why long long int?
... const int xsize,const int ysize ...
for(long long int i = 0; i <(xsize * ysize); i++)
... const int xsize,const int ysize ...
for(long long int i = 0; i <(xsize * ysize); i++) // Why long long int?
added 128 characters in body
Source Link
chux
  • 36.5k
  • 2
  • 43
  • 97

Likewise problem with

unsigned char header[54];
...
unsigned long output;
output = header[18] + (header[19] << 8) + ( header[20] << 16) + ( header[21] << 24);

header[18] + (header[19] << 8) + ( header[20] << 16) + ( header[21] << 24) is computed using int math.

Alternative:

unsigned long output = header[18] + 
    ((unsigned long)header[19] << 8) + 
    ((unsigned long)header[20] << 16) + 
    ((unsigned long)header[21] << 24);

Here also, I'd consider size_t rather than unsigned long.

Likewise problem with

unsigned char header[54];
...
unsigned long output;
output = header[18] + (header[19] << 8) + ( header[20] << 16) + ( header[21] << 24);

header[18] + (header[19] << 8) + ( header[20] << 16) + ( header[21] << 24) is computed using int math.

Alternative:

unsigned long output = header[18] + 
    ((unsigned long)header[19] << 8) + 
    ((unsigned long)header[20] << 16) + 
    ((unsigned long)header[21] << 24);

Here also, I'd consider size_t rather than unsigned long.

added 128 characters in body
Source Link
chux
  • 36.5k
  • 2
  • 43
  • 97

const parameters

This is not about the const in const RGB *.

Curious code uses const int xsize, but not const RGB * const image as neither xsize nor RGB changes.

If one is using const to help prevent changes to unchanging parameters, be consistent.

// RGB *MedianFilter33(const RGB *image,const int xsize,const int ysize)
RGB *MedianFilter33(const RGB * const image, const int xsize, const int ysize)

IMO: these const tend to be more error prone/obfuscation than worth it as they are noise in a .h function declaration.

// Suggested:
RGB *MedianFilter33(const RGB *image, int xsize, int ysize)

int vs. long long

For array sizing consider size_t and a C2x paradigmprinciple: put dimensions first.

For

// RGB *MedianFilter33(const RGB *image,const int xsize,const int ysize)
RGB *MedianFilter33(size_t xsize, size_t ysize, const RGB *image)

int vs. long long

For array sizing consider size_t and C2x paradigm

For

const parameters

This is not about the const in const RGB *.

Curious code uses const int xsize, but not const RGB * const image as neither xsize nor RGB changes.

If one is using const to help prevent changes to unchanging parameters, be consistent.

// RGB *MedianFilter33(const RGB *image,const int xsize,const int ysize)
RGB *MedianFilter33(const RGB * const image, const int xsize, const int ysize)

IMO: these const tend to be more error prone/obfuscation than worth it as they are noise in a .h function declaration.

// Suggested:
RGB *MedianFilter33(const RGB *image, int xsize, int ysize)

int vs. long long

For array sizing consider size_t and a C2x principle: put dimensions first.

// RGB *MedianFilter33(const RGB *image,const int xsize,const int ysize)
RGB *MedianFilter33(size_t xsize, size_t ysize, const RGB *image)
added 128 characters in body
Source Link
chux
  • 36.5k
  • 2
  • 43
  • 97
Loading
added 128 characters in body
Source Link
chux
  • 36.5k
  • 2
  • 43
  • 97
Loading
Typo fix
Source Link
Toby Speight
  • 88.5k
  • 14
  • 104
  • 327
Loading
Source Link
chux
  • 36.5k
  • 2
  • 43
  • 97
Loading