cc65: Problem with static locals?

Maybe I’m missing something (at least it’s Monday), but the following code prints only “0” for “cx” while I think it shouldn’t:

#include <stdio.h>

unsigned char x=0;

void
PrintVar(void)
{
	unsigned char cx = x+1;
	printf("cx: %d\n", cx);
}


void
main(void)
{
	do
	{
		++x;
		PrintVar();
	}
	while(1);
}

Executable created only with the “-Cl” option. Without it, it works ok.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 17 (17 by maintainers)

Commits related to this issue

Most upvoted comments

cheers 😃

I’ll take a look.

EDIT: What does -Cl really do?

@mrdudz Thanks for the explanation.

@acqn HELP! 😃