Need help with writing function

Hey guys, I'm new here and need some help with some code as my knowledge in C++ is rusty. I need some assistance in writing a function as what I've written so far won't compile and I'm not sure how to fix the issue.

My code:

int* a;
int* b;
int* c;
int* d;
int* x;

void setup() {
  pinMode(&a, OUTPUT);
  pinMode(&b, OUTPUT);
  pinMode(&c, OUTPUT);
  pinMode(&d, OUTPUT); 
}

void loop() {
  
  void NixieOutput(&a, &b, &c, &d, &x)
  {
    if(&x = 0)
    {
       //0
      digitalWrite(&a, LOW);
      digitalWrite(&b, LOW);
      digitalWrite(&c, LOW);
      digitalWrite(&d, LOW);
    }
    
    if(&x = 1)
    {
      //1
      digitalWrite(&a, LOW);
      digitalWrite(&b, LOW);
      digitalWrite(&c, LOW);
      digitalWrite(&d, HIGH);
    }
    
    if(&x = 2)
    {
      //2
      digitalWrite(&a, LOW);
      digitalWrite(&b, LOW);
      digitalWrite(&c, HIGH);
      digitalWrite(&d, LOW);
    }
    
    if(&x = 3)
    {
      //3
      digitalWrite(&a, LOW);
      digitalWrite(&b, LOW);
      digitalWrite(&c, HIGH);
      digitalWrite(&d, HIGH);
    }
    
    if(&x = 4)
    {
      //4
      digitalWrite(&a, LOW);
      digitalWrite(&b, HIGH);
      digitalWrite(&c, LOW);
      digitalWrite(&d, LOW);
    }
    
    if(&x = 5)
    {
      //5
      digitalWrite(&a, LOW);
      digitalWrite(&b, HIGH);
      digitalWrite(&c, LOW);
      digitalWrite(&d, HIGH);
    }
    
    if(&x = 6)
    {
      //6
      digitalWrite(&a, LOW);
      digitalWrite(&b, HIGH);
      digitalWrite(&c, HIGH);
      digitalWrite(&d, LOW);
    }
    
    if(&x = 7)
    {
      //7
      digitalWrite(&a, LOW);
      digitalWrite(&b, HIGH);
      digitalWrite(&c, HIGH);
      digitalWrite(&d, HIGH);
    }
    
    if(&x = 8)
    {
      //8
      digitalWrite(&a, HIGH);
      digitalWrite(&b, LOW);
      digitalWrite(&c, LOW);
      digitalWrite(&d, LOW);
    }
    
    if(&x = 9)
    {
      //9
      digitalWrite(&a, HIGH);
      digitalWrite(&b, LOW);
      digitalWrite(&c, LOW);
      digitalWrite(&d, HIGH);
    }
    
  }
  
    
}

The error I keep getting is "variable or field 'NixieOutput' declared void".
The objective of the function is to control a nixie tube digitally with a BCD to decimal decoder. I had it working (I think) when I was coding the output directly in the main file but I want to make a function that I pass 4 pins to plus a decimal number and it sets the output that way the main code isn't so long and messy. Dumb dumb me had something connected wrong and thus I accidentally fried my board but it did work for a few seconds. All I had it do was change the number displayed once per second.

Anyways thanks for any help. I'm having fun getting back into programming!

C++ doesn't allow functions to be defined inside other functions.

Oh ok. I was trying to follow to function tutorial I found on arduinos site. Moving the function from the loop function though I still get the same error.

So post your updated code. Also, you want == inside your if statements.

Ah darn it! Thanks for the reminder about the == for the if statements. Nub mistake on my part. Anyways here's my code and as it sits now I still get the same error message.

int* a;
int* b;
int* c;
int* d;
int* x;



void setup() {
  pinMode(&a, OUTPUT);
  pinMode(&b, OUTPUT);
  pinMode(&c, OUTPUT);
  pinMode(&d, OUTPUT);
  

}

void loop() {
}
void NixieOutput(&a, &b, &c, &d, &x)
  {
    if(&x == 0)
    {
       //0
      digitalWrite(&a, LOW);
      digitalWrite(&b, LOW);
      digitalWrite(&c, LOW);
      digitalWrite(&d, LOW);
    }
   
    if(&x == 1)
    {
      //1
      digitalWrite(&a, LOW);
      digitalWrite(&b, LOW);
      digitalWrite(&c, LOW);
      digitalWrite(&d, HIGH);
    }
   
    if(&x == 2)
    {
      //2
      digitalWrite(&a, LOW);
      digitalWrite(&b, LOW);
      digitalWrite(&c, HIGH);
      digitalWrite(&d, LOW);
    }
   
    if(&x == 3)
    {
      //3
      digitalWrite(&a, LOW);
      digitalWrite(&b, LOW);
      digitalWrite(&c, HIGH);
      digitalWrite(&d, HIGH);
    }
   
    if(&x == 4)
    {
      //4
      digitalWrite(&a, LOW);
      digitalWrite(&b, HIGH);
      digitalWrite(&c, LOW);
      digitalWrite(&d, LOW);
    }
   
    if(&x == 5)
    {
      //5
      digitalWrite(&a, LOW);
      digitalWrite(&b, HIGH);
      digitalWrite(&c, LOW);
      digitalWrite(&d, HIGH);
    }
   
    if(&x == 6)
    {
      //6
      digitalWrite(&a, LOW);
      digitalWrite(&b, HIGH);
      digitalWrite(&c, HIGH);
      digitalWrite(&d, LOW);
    }
   
    if(&x == 7)
    {
      //7
      digitalWrite(&a, LOW);
      digitalWrite(&b, HIGH);
      digitalWrite(&c, HIGH);
      digitalWrite(&d, HIGH);
    }
   
    if(&x == 8)
    {
      //8
      digitalWrite(&a, HIGH);
      digitalWrite(&b, LOW);
      digitalWrite(&c, LOW);
      digitalWrite(&d, LOW);
    }
   
    if(&x == 9)
    {
      //9
      digitalWrite(&a, HIGH);
      digitalWrite(&b, LOW);
      digitalWrite(&c, LOW);
      digitalWrite(&d, HIGH);
    }
   
  }

You have an awful lot of these in your code:

&

And a few of these:

*

As far as I can see, you would be better off with none of either.

if you want to use pointers * then you reference to them with pointers * not the adress &. Also you need to define the type of your function parameters. Then it compiles. Unless you have a good reason to use pointers I would just skip them.

int* a;
int* b;
int* c;
int* d;
int* x;

void setup() {
  pinMode(*a, OUTPUT);
  pinMode(*b, OUTPUT);
  pinMode(*c, OUTPUT);
  pinMode(*d, OUTPUT);
}

void loop() {}

void NixieOutput(int *a, int *b, int *c, int *d, int *x)  {
    if(*x == 0){
       //0
      digitalWrite(*a, LOW);
      digitalWrite(*b, LOW);
      digitalWrite(*c, LOW);
      digitalWrite(*d, LOW);
    }
   
    if(*x == 1){
      //1
      digitalWrite(*a, LOW);
      digitalWrite(*b, LOW);
      digitalWrite(*c, LOW);
      digitalWrite(*d, HIGH);
    }
   
    if(*x == 2) {
      //2
      digitalWrite(*a, LOW);
      digitalWrite(*b, LOW);
      digitalWrite(*c, HIGH);
      digitalWrite(*d, LOW);
    }
   
    if(*x == 3) {
      //3
      digitalWrite(*a, LOW);
      digitalWrite(*b, LOW);
      digitalWrite(*c, HIGH);
      digitalWrite(*d, HIGH);
    }
   
    if(*x == 4)  {
      //4
      digitalWrite(*a, LOW);
      digitalWrite(*b, HIGH);
      digitalWrite(*c, LOW);
      digitalWrite(*d, LOW);
    }
   
    if(*x == 5){
      //5
      digitalWrite(*a, LOW);
      digitalWrite(*b, HIGH);
      digitalWrite(*c, LOW);
      digitalWrite(*d, HIGH);
    }
   
    if(*x == 6)   {
      //6
      digitalWrite(*a, LOW);
      digitalWrite(*b, HIGH);
      digitalWrite(*c, HIGH);
      digitalWrite(*d, LOW);
    }
   
    if(*x == 7)   {
      //7
      digitalWrite(*a, LOW);
      digitalWrite(*b, HIGH);
      digitalWrite(*c, HIGH);
      digitalWrite(*d, HIGH);
    }
   
    if(*x == 8) {
      //8
      digitalWrite(*a, HIGH);
      digitalWrite(*b, LOW);
      digitalWrite(*c, LOW);
      digitalWrite(*d, LOW);
    }
   
    if(*x == 9) {
      //9
      digitalWrite(*a, HIGH);
      digitalWrite(*b, LOW);
      digitalWrite(*c, LOW);
      digitalWrite(*d, HIGH);
    }
  }

My objective was to have this function sit in it's own .h file that I can #include so it keeps the main file nice and clean. I thought pointers were needed for this? Sorry for the noob questions pointers were difficult for me back when I studied C++ a bit and that was a few years ago.

You shouldn't ever put the body of a function in a .h file.

Explain why you think pointers are necessary, please.

I think most people are suggesting that you probably don't need to pass any of these values by reference (no pointers necessary). You would pass a variable by reference if you wanted to change the data in that variable that had been defined in another scope.

When building an arduino library, it is not a necessity to use pointers. You would only use them if you wanted to pass the location in memory where data is stored not to move functions to a library.

This is a good tutorial to get you started on creating your own library. https://www.arduino.cc/en/Hacking/LibraryTutorial

Before writing your own library, I would suggest getting your functions compiling and running properly in your sketch. Then once your sketch is becoming large you can move like functions into a library using the tutorial (or into a class then into a library). That way you can make small steps to confirm your code.

You could put your Nixie stuff into its own separate cpp file. Create a .h file with extern references to your nixie functions and include it in your top-level ino file.

If you want to use pointers to your pins you could do something like this (compiles, not tested...)

int
    a=2,
    b=3,
    c=4,
    d=5;
int
    x;
    
void setup() 
{
    pinMode( a, OUTPUT );
    pinMode( b, OUTPUT );
    pinMode( c, OUTPUT );
    pinMode( d, OUTPUT );
    x = 0;
    
}

void loop( void )
{
    static uint32_t
        timeNixie = 0;
    uint32_t
        timeNow;

    timeNow = millis();
    if( timeNow - timeNixie > 1000 )
    {
        timeNixie = timeNow;
        NixieOutput( &a, &b, &c, &d, &x);
        if( x < 9 )
            x++;
        else
            x = 0;
    }//if
       
}//loop

void NixieOutput( int *a, int *b, int *c, int *d, int *x)
{
    digitalWrite( *d, (*x & 0x08)?HIGH:LOW );
    digitalWrite( *c, (*x & 0x04)?HIGH:LOW );
    digitalWrite( *b, (*x & 0x02)?HIGH:LOW );
    digitalWrite( *a, (*x & 0x01)?HIGH:LOW ); 
    
}//NixieOutput