I don't know Cosmic, but it seems that the problem could be related to static initialization. If you declare a variable as const it will likely end up in flash, and if ou don't declare it as const, it will likely end up in RAM. And then, if you pick a minimal non-standard startup code as is custom with most embedded compilers, the variable won't be initialized and contain garbage values.