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

const-qualify variable to suppress compiler warning #121

Open
escherstair opened this issue Jan 10, 2024 · 3 comments
Open

const-qualify variable to suppress compiler warning #121

escherstair opened this issue Jan 10, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@escherstair
Copy link

I get a warning/suggestion from the compiler because in the following function
https://github.com/ARM-software/CMSIS_5/blob/a75f01746df18bb5b929dfb8dc6c9407fac3a0f3/CMSIS/Core/Include/core_cm7.h#L2195-L2199

in the line

  uint32_t *vectors = (uint32_t *)SCB->VTOR;

the pointer vectors can/should be defines as pointer-to-const

  const uint32_t *vectors = (const uint32_t *)SCB->VTOR;

I think that the same change can be applied to all the other core_cmXXX.h files

@JonatanAntoni JonatanAntoni transferred this issue from ARM-software/CMSIS_5 Jan 10, 2024
@JonatanAntoni JonatanAntoni added the enhancement New feature or request label Jan 10, 2024
@JonatanAntoni
Copy link
Member

Hi @escherstair,

Thanks for pointing this out. I moved your proposal to CMSIS 6 as this should be the place to make such enhancements.

I wonder if uint32_t is the correct type at all. Unfortunately, changing type to void(*VECTOR_TABLE_Type)(void) would be a breaking change.

@ReinhardKeil
Copy link
Contributor

@escherstair which compiler are you using. SCB->VTOR can also point to a RAM based vector table. Is in this case (const uint32_t *) the right definition?

It may depend therefore depend on global compiler optimizations and other usage of SCB->VTOR in your application.

@escherstair
Copy link
Author

@ReinhardKeil the suggestion is only related to adding const.
The type was uint32_t* and I don't want to change it.
The function

__STATIC_INLINE uint32_t __NVIC_GetVector(IRQn_Type IRQn)
{
  uint32_t *vectors = (uint32_t *)SCB->VTOR;
  return vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET];
}

doesn't change the value pointed by *vectors, but it returns it.
And so a pointer-to-const should be preferred.

I use AC6 with maximum warnings, combined with cppcheck + clang-tidy analysis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants