3

Having just started out developing for the Pebble app - and also returning to my very basic C skills which has not been maintained for many many years, I am trying to understand the basic structure of these Pebble apps.

I do know the difference between static and nonstatic, but would be very happy if anyone could help shed some light on the impact on my application in this case. I have pasted minimized example code below, which shows how the Pebble app is structured in the two cases.

Static version

#include <pebble.h>

static Window *window;

static void handle_init(void) {
    window = window_create();
    window_stack_push(window, true);

}

static void handle_deinit(void) {
    window_destroy(window);
}

int main(void) {
    handle_init();
    app_event_loop();
    handle_deinit();
}

Non-static version

#include <pebble.h>

Window *window;

void handle_init(void) {
    window = window_create();
    window_stack_push(window, true);

}

void handle_deinit(void) {
    window_destroy(window);
}

int main(void) {
    handle_init();
    app_event_loop();
    handle_deinit();
}

My question is this:

What's the implications of using nonstatic vs static variables and functions?

I have tried to find information on the Pebble developer site, but static and non-static examples seems be be used without much consistency and I have failed to find a good official guideline.

Jaran
  • 313
  • 1
  • 2
  • 10

1 Answers1

9

It has to do with linkage and visibility. In short, global symbols marked static are not exported from the translation unit (source file) it's defined in. That means if you have multiple source files in your project, if you declare a global variable or function static in one file, that variable or function can't be "seen" or used from any other source file.

And this is (or should be) basic C knowledge, nothing special to do with Pebble.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • 1
    Thanks for clarifying - answered my question. I had a feeling this was basic C knowledge, however I was unsure whether it may be any specific pattern related to Pebble development. – Jaran Sep 29 '14 at 11:33