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

Update dlt_for_developers.md #405

Merged
merged 1 commit into from
Sep 28, 2022
Merged

Conversation

marques-bruno
Copy link
Contributor

Fix error in suggested best-practice code snippet

Fix error in suggested best-practice code snippet
@michael-methner
Copy link
Collaborator

Hello @marques-bruno ,
the declaration of a variable in the for loop is allowed since C99.

@marques-bruno
Copy link
Contributor Author

marques-bruno commented Sep 27, 2022

@michael-methner the issue here is not the declaration of the variable inside the for statement, but the fact that the lifespan of that variable is bound to the scope of the for variable.
If this code might compile depending on the compiler, the index variable's content is undefined outside of the loop's scope.
Thus, the log message at line 235 won't work as expected:

LOG("Loop count: %d", index);

I know this is just a snippet in the documentation, but it is presented as best practice for DLT users, and therefore might be simply copy-pasted into production code. Since some compilers might not detect this as an error, it is probably best to correct it...

@michael-methner michael-methner merged commit 26dd01c into COVESA:master Sep 28, 2022
@michael-methner
Copy link
Collaborator

Hello @marques-bruno , thanks for the hint. that line was hidden in the diff.

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

Successfully merging this pull request may close these issues.

2 participants