Removing argument names from shiftout() declare

I’m new to arduino. I just wrote my first shift register program but I found a hidden trap. Here is what I did:

  1. I defined a few pre-compile macros with #define
    #define clockPin 10
  2. I compiled the program and it failed to compile.

Here’s the problem. I think when I did the #define, the complier replaced the clockPin in the wiring.h with 10. Here’s the original line:

void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, byte val);

This was a simple mistake but took me a while to realize since the complier error messages are not always to the point.

I think, since one is not required to name the arguments of a declared function until the function is actually defined, why don’t we remove those names from the above line and make it read this way?

void shiftOut(uint8_t, uint8_t, uint8_t, byte);

Is this doable with the corrent complier or are the developers leaving these names to remind themselves? Thanks. ::slight_smile:

Good spot, and glad you found out how to fix it yourself.

I always name the arguments in prototypes, for the reason you stated last. The header file containing function prototypes becomes a form of documentation or quick-reference guide for the library or module of a program.

When in doubt, which is clearer?

void memset(void*,int,int);
void memset(void* buffer, int data, int length);

It was a quick example-- someone might say "but they really use type size_t for the third argument!" However, I think you get the idea, and I see much more confusing prototypes (like your question) all the time.

Source code is more for the human's benefit than for the machine's benefit. Make it readable. Make it clear.

As for your specific situation, most experienced C coders define constants in ALLCAPS, and don't do that for other symbols, to avoid the problem.

#define LED_PIN 9
// :
pinMode(LED_PIN, OUTPUT);

Thanks halley. It always helps to communicate with the creater of the codes. I can certainly adopt an all-caps convention. I just happened to have copied the example code from the reference page and decided to define the clockPin etc. under #define to save ram. Now that I know my problem, I have used myName for all Names that I suspect to have conflict with headers.

Boy, I agree with halley on this one. You consult, say, the SoftwareSerial header to remind you which pin comes first in the constructor, and here's the declaration:

SoftwareSerial(uint8_t, uint8_t);

D'Oh! That's no help!! I'd much prefer that names be included in all declarations.

I use the all-caps technique too, but it occurred to me that this case is another good argument for using

static const int LED_PIN = 9;

Mikal