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

Missing break in switch-case? #257

Closed
Schildkroet opened this issue Jan 25, 2024 · 1 comment
Closed

Missing break in switch-case? #257

Schildkroet opened this issue Jan 25, 2024 · 1 comment

Comments

@Schildkroet
Copy link

Hello,
is it intended, that there is no break for each case here?

nanoprintf/nanoprintf.h

Lines 402 to 407 in 64333b3

case 'i':
case 'd': tmp_conv = NPF_FMT_SPEC_CONV_SIGNED_INT;
case 'o': if (tmp_conv == -1) { tmp_conv = NPF_FMT_SPEC_CONV_OCTAL; }
case 'u': if (tmp_conv == -1) { tmp_conv = NPF_FMT_SPEC_CONV_UNSIGNED_INT; }
case 'X': if (tmp_conv == -1) { out_spec->case_adjust = 0; }
case 'x': if (tmp_conv == -1) { tmp_conv = NPF_FMT_SPEC_CONV_HEX_INT; }

@charlesnicholson
Copy link
Owner

Yeah, it's intended fall-through; each case is guarded by tmp_conv during the fall-through. It's also awful and ridiculous and stupid, but arm-gcc knows exactly what to do with it.

The underlying issue was that nanoprintf was non-conformant: the C standard requires that printf + friends ignore the 0 flag when precision is specified, so you need to do some special-casing iff an integer type and 0 and precision were specified. That could have been a separate if statement with a bunch of or sub-clauses after the switch case, but it added ~100 bytes to the compiled code on cortex-m0 architectures. So, I did a disgusting Duff's-Device-ish thing here, and it ended up being a freebie in terms of size.

#244
https://github.com/charlesnicholson/nanoprintf/pull/245/files

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

2 participants