0

I have an issue compiling my pebble watchapp. I am trying to send strings to the Pebbl eJS script on the phone lihe this:

Tuplet password_tuple = TupletCString(PASSWORD_KEY, password_str);
Tuplet email_tuple = TupletCString(EMAIL_KEY, email_str); 

The compiler error is: (they both error out like this, this is just one of the lines of output below)

./src/app_test.c:84:25: error: the address of 'email_str' will always evaluate as 'true'   [-Werror=address]

email_str and password_str are defined at the top of the program, like this:

static char email_str[30];
static char password_str[30];
#define PASSWORD_PKEY (int32_t)21
#define EMAIL_PKEY (int32_t)20

Does anyone notice anything wrong with this?

med116
  • 1,526
  • 17
  • 16

2 Answers2

3

@ismail-badawi answer is very correct.

Pebble now recommends that you use dict_write_cstring.

dict_write_cstring(&iter, SOME_STRING_KEY, string);
sarfata
  • 4,625
  • 4
  • 28
  • 36
2

Well it's certainly not obvious, but it turns out it's because TupletCString is a macro, and it'll expand to an expression that contains email_str ? strlen(email_str) + 1 : 0 as a subexpression, and this is what causes the error, because email_str can't be null and so the comparison isn't doing anything.

I found this thread on the Pebble forums with an explanation. The suggested fix is to define your own macro that doesn't have a conditional, e.g.

#define MyTupletCString(_key, _cstring) \
((const Tuplet) { .type = TUPLE_CSTRING, .key = _key, .cstring = { .data = _cstring, .length = strlen(_cstring) + 1 }})
Ismail Badawi
  • 36,054
  • 7
  • 85
  • 97