parameters by reference (pointers)

Call me crazy,
but I am having a very difficult time passing a structure pointer as a parameter.

I am passing structs, which yes probably complicates it a little but I really don’t know what is wrong. I know C/C++ and am just trying to figure out how this lang works.

In the .h :

struct time {
int hour;
int minute;
int second;
int month;
int day_of_week;
int day;
int year;
};

in the .cpp :

void readTime(time *retTime) {
}

Compiler says:
error: variable or field ‘readTime’ declared void In function ‘void readTime(time*)’:

I am at a loss! I’m not even calling the thing.
on the note of parameters:

Can I pass a c++ style reference? void function(int &refInt);
Can I pass a struct / class pointer? I know they are the same in c++ but I’m not sure with this environment. Based on what I just posted it looks like I can’t.

Thanks!
Lucas

I'm not a C++ expert or anything close to one, lol. But the only way I could really get it to compile corretly is buy just using

time * readTime(time * retTime);

instead of

void readTime(time * retTime);

It seemed to work just using int * to define the function type as well.

that's so weird tho, I'm not returning anything?

that would define a program that takes a pointer and returns a pointer of the same type.

strange, thanks tho!!

anyone else have some insight?

If you are running that code in the primary sketch tab, then I suspect the Arduino IDE auto-prototyping is mangling the definition of readTime. Have you tried it in a seperate cpp in a second tab?

If you are running that code in the primary sketch tab, then I suspect the Arduino IDE auto-prototyping is mangling the definition of readTime. Have you tried it in a seperate cpp in a second tab?

Added a new .cpp in a seporate tab and moved the code over there. Got a few issues so I only left the definition for void readTime(time * retTime); and got the same error.

Tried downloading Arduino 009, as I was using 007 - same issue.

Since you say Arduino auto prototypes I tried removing my prototypes and I get the same error.

I'm about to use global variables, but that's going to make that code sloppy.

Any other ideas?

Thanks

I tried:

struct time { 
  int hour; 
  int minute; 
  int second; 
  int month; 
  int day_of_week; 
  int day; 
  int year; 
}; 

void readTime(time *retTime);

in an h file and :

void readTime(time *retTime) { 
   // this needs to be in a cpp file in a seperate tab.
}

in a cpp file in another tab and it compiled ok in verison 0010

BTW, I don’t think it makes any difference to the error you are getting, but the following seems clearer to me:

typedef struct {
int hour;
int minute;
int second;
int month;
int day_of_week;
int day;
int year;
} time ;

I think the syntax should be

void readTime(struct time *retTime) {

instead of

void readTime(time *retTime) {

don't recall for sure, and all my reference books are at the office.

-j

Compiler says: error: variable or field 'readTime' declared void In function 'void readTime(time*)':

In a situation like this, it's worth setting the build.verbose option in the preferences file to true, re-compiling and then re-running from the command line the last command listed in the monitor pane. This will often give more detail on where the error is coming from. (You can also look directly at the temporary files generated.)

I wouldn't be suprised if auto-prototype generation was causing an issue but we'd really need to see your exact code to be able to track down the issue reliably.

Can I pass a c++ style reference? void function(int &refInt);

I've used C++ style references in Arduino sketches before--they work as long as you play by the rules.

--Phil.

Thanks everyone,
but still no luck.

I turned on verbose logging but didn’t see any new info to put in a command prompt.
I am working with Arduino 11 now.

I looked at the temporary build folder and the .cpp / .h 's there seem fine, do not look garbled. I can not analyze the .o

here is the exact code I am currently working with.

All the files are included as part of the tank_final project and reside in the same folder as the .pde file.
Files are “tank.cpp” “tank.h” and the main window

With this exact setup on Arduino 11 I still see:
error: variable or field ‘readTime’ declared void

“tank.h” :

#define SHIFT_OUT                4
#define SHIFT_REGISTER_CLOCK     5
#define SHIFT_CLOCK              6



#define SENSOR_CLOCK             2
#define SENSOR_DATA              3

#define readHumMask              B00000101
#define readTempMask             B00000011
#define clearMask                B00011110
#define readStatusMask           B00000111
#define writeStatusMask          B00000110
#define softResetMask            B00011110
#define heatOn                   B00000100
#define heatOff                  0


typedef struct {
  int hour;
  int minute;
  int second;
  int month;
  int day_of_week;
  int day;
  int year;
} time;



// TIME
void readTime(time *retTime);

“tank.cpp” :

#include <Wire.h>


void readTime(time *retTime) {
  
  int hour;
  int minute;
  int second;
  int month;
  int day_of_week;
  int day;
  int year;
  
  // Below required to reset the register address to 0.
  Wire.beginTransmission(104); // transmit to device #104, the ds 1307
  Wire.send(0x00);
  Wire.endTransmission();    // stop transmitting
 
  Wire.requestFrom(104, 7);    // request 7 bytes from slave ds1307, we'll assume it'll send them all even though it doesn't have to
  second = Wire.receive();  
  minute = Wire.receive();  
  hour = Wire.receive();  
  day_of_week=Wire.receive();  
  day = Wire.receive();  
  month = Wire.receive();  
  year = Wire.receive();  
 
  // Convert all the BCD values that might have "tens" to decimal.  Most arduino folks do this w/shifts but this just looks easier to me.
  hour=hour/16 * 10 + hour % 16;
  minute=minute/16 * 10 + minute % 16;
  second=second/16 * 10 + second % 16;
  day=day/16 * 10 + day % 16;
  month=month/16 * 10 + month % 16;
  year=2000 + year/16 * 10 + year % 16;
   
  Serial.print(hour);
  Serial.print(":");
  if (minute < 10) { Serial.print("0"); }
  Serial.print(minute);
  Serial.print(":");
  if (second < 10) { Serial.print("0"); }
  Serial.print(second);
  Serial.print(" ");
  Serial.print(dow[day_of_week-1]);  // array is 0-6, but the dow register holds 1-7, so subtract 1.
  Serial.print(", ");
  Serial.print(month);
  Serial.print("/");
  Serial.print(day);
  Serial.print("/");
  Serial.print(year);
  Serial.print("\n");
  
  retTime->hour = hour;
  retTime->minute = minute;
  retTime->second = second;
  retTime->month = month;
  retTime->day_of_week = day_of_week;
  retTime->day = day;
  retTime->year = year;


}

Main Window:

#include <Wire.h>
#include "Tank.h"

//remove later, for testing
byte mask1 = B10101010;
byte mask2 = B01010101;

char* dow[7] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

 
void setup() {

  Wire.begin();
  Serial.begin(9600);

  // shift register (LED) outputs
  pinMode(SHIFT_REGISTER_CLOCK, OUTPUT);
  pinMode(SHIFT_CLOCK, OUTPUT);
  pinMode(SHIFT_OUT, OUTPUT);
}

void loop() {
  
  //time curTime;
  //envStatus environment;

  //write_led_mask(mask1);
  delay(1000);
  
  //write_led_mask(mask2);    
  delay(1000);
  
  Serial.println("SSS on sensor");
  // remember deal with the heat and what not
  Serial.println("TTT on time");
}

You need to #include "tank.h" from tank.cpp. You might also have some other errors, but they should be relatively straightforward.

You need to #include "tank.h" from tank.cpp. You might also have some other errors, but they should be relatively straightforward.

Works! thanks