Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

word() cast not working #360

Closed
rpseng opened this issue May 30, 2015 · 6 comments
Closed

word() cast not working #360

rpseng opened this issue May 30, 2015 · 6 comments

Comments

@rpseng
Copy link

rpseng commented May 30, 2015

Dear all, first let me say that you are doing a great job on this!

The bug I found is very simple to reproduce with the following sketch:

void setup() {
uint8_t data = 1;
uint16_t data16 = word(data);
}
void loop() {
}

With the above code I'm getting unresolved symbols in the link step:
undefined reference to `makeWord(unsigned short)'

That should be probably easy to fix, but I don't know where...
I reproduced this problem on both Linux and Windows. For standard Arduino the code links fine.

The following equivalent code links fine with the esp8266:
void setup() {
uint8_t data = 1;
uint16_t data16 = uint16_t(data);
}
void loop() {
}

All the best.

@chadouming
Copy link
Contributor

that's not how you cast in c++ .

this is how:
uint8_t data = 1;
uint16_t data16 = (word)data;

@Makuna
Copy link
Collaborator

Makuna commented May 31, 2015

See static_cast<>(), dynamic_cast, and reinterpret_cast, const_cast for the modern way.

@rpseng
Copy link
Author

rpseng commented May 31, 2015

Thanks for the advise:
uint16_t data16 = (word)data;

This indeed also fixes the problem. Anyway, the compiler should complain instead of giving a link problem. This was a real pain to debug, it actually shown up when I was trying to port the ModbusMaster library to esp8266.

All the best.

@chadouming
Copy link
Contributor

Well, word(something) for the compiler mean you are trying to use the
function word with something argument, so it's normal behavior to say it's
not found.

On Sun, May 31, 2015, 7:55 AM Rafael de Pelegrini Soares <
notifications@github.com> wrote:

Thanks for the advise:
uint16_t data16 = (word)data;

This indeed also fixes the problem. Anyway, the compiler should complain
instead of giving a link problem. This was a real pain to debug, it
actually shown up when I was trying to port the ModbusMaster library to
esp8266.

All the best.


Reply to this email directly or view it on GitHub
#360 (comment).

@rpseng
Copy link
Author

rpseng commented May 31, 2015

I agree that word(something) means a function call. The problem with that particular case is that the linker complains about 'makeWord' missing and not the original function 'word'. Thus, the compiler somehow understand this, but get confused in the link step... BTW, it works with the standard arduino compiler, the problem appears only with the esp version.

@Makuna
Copy link
Collaborator

Makuna commented Jun 1, 2015

I believe the original intent of the makeWord was not specifically for casting, it was meant as a means to abstract "making a word" from two bytes (endian abstraction).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants