Go Down

Topic: "Correct" method for migrating libs to Arduino 1.0 (Read 4 times) previous topic - next topic

pYro_65

or create a file 'WProgram.h' in the 1.0 core directory 'D:\PathToArduino\hardware\arduino\cores\arduino'

and put inside it

Code: [Select]

#include "Arduino.h"


and just for gcc compiler optimisation you could also put


Code: [Select]

#ifndef HEADER_WPROGRAM
  #define HEADER_WPROGRAM
  #include "Arduino.h"
#endif


this will fix most libraries.

liudr

I am having some trouble with the lcd.write method. I had no problem with this method and now with 1.0

Error: " candidates are: virtual size_t LiquidCrystal::write(uint8_t)"

So what should I do? Change all write to print?

PaulS

Quote
So what should I do? Change all write to print?

Altogether now: "Post the code that generates the error!"

liudr


Quote
So what should I do? Change all write to print?

Altogether now: "Post the code that generates the error!"


Code: [Select]

#include <LiquidCrystal.h>

LiquidCrystal LCD(2,3,4,5,6,7);
void setup()
{
  LCD.begin(16,2);
  LCD.write((uint8_t)'\0');
}
void loop()
{}


The above code, when compiled in 1.0, only works with the type case (uint8_t) but works without it in 0022. I traced the library code to the following:

arduino 0022 LiquidCrystal.cpp:
Code: [Select]
inline void LiquidCrystal::write(uint8_t value) {
  send(value, HIGH);
}


arduino 1.0 LiquidCrystal.cpp:
Code: [Select]
inline size_t LiquidCrystal::write(uint8_t value) {
  send(value, HIGH);
  return 1; // assume sucess <- TYPO Anyone proofread the library???
}


I'm stuck on why using write('\0') won't work in 1.0

The LiquidCrystal.h is fine but 0022 and 1.0

There must be a type cast in 0022 that casts all (const char) into uint8_t in some place that the 1.0 is missing, right?

maniacbug

#9
Dec 20, 2011, 07:37 am Last Edit: Dec 20, 2011, 07:41 am by maniacbug Reason: 1
The cause here is something SUPER subtle.  It really should never have worked. The full text of the error message is listed below.  Indeed, it tells the truth.  It cannot tell if you mean to call 'write' with '0' as a uint8_t or 'write' with '0' as a null pointer.

Code: [Select]

something.pde:66: error: call of overloaded 'write(int)' is ambiguous
/opt/Arduino/master/libraries/LiquidCrystal/LiquidCrystal.h:82: note: candidates are: virtual size_t LiquidCrystal::write(uint8_t)
/opt/Arduino/master/hardware/arduino/cores/arduino/Print.h:49: note:                 size_t Print::write(const char*)


This is going on my list of interview questions :)  The super subtle difference is that in 1.0, Print::write(const char *str) is no longer virtual.  In 0022, it's virtual.  So in 0022, the compiler is trying to resolve what you mean by LiquidCrystal::write(0).  As there is only one method actually declared as a LiquidCrystal member, it can pick write(uint8_t).  It can de-prioritize the virtual write(const char*) that is only in the base class. However, in 1.0, it's more confusing, because write(const char*) is a first-class member of LiquidCrystal due to it not being virtual.  So the compiler's choice is no longer obvious.

Anyway, you're in the clear for library compat.  Just use (uint8_t)0 and you'll be safe in both cases.


Go Up