Hi Greg,
I apologize for the slightly misleading example I provided. It was just a
simple example name for a function that would let the people viewing it
know it doesn't modify anything.
A better example would be something like this:
ssize_t mfs_read_page(FAR const struct mfs_sb_s * const sb,
Hi all,
First up, I am extremely sorry for the late response. I traveled the entire
day and finally reached a place with network coverage.
Thank you, Michal, this clears up my confusion. I was wondering if the
compiler is smart enough for more complex cases.
And compiler can easily determine if
That is correct. I was not suggesting to change the interface. We were
only using read() as an example.
We were basically saying this:
If a function promises not to modify a buffer, its definition should
contain const like this:
void function_that_does_not_modify_buffer(const uint8_t * buffer);
The prototypes of standard interface functions are specified in the
POSIX standard. It would be a POSIX violation to use whatever prototype
you happen to like most. No one gets to "improve" POSIX.
read() is specified here
https://pubs.opengroup.org/onlinepubs/9699919799/functions/read.html
Replying inline below...
On Sat, Jul 13, 2024 at 3:21 PM Petro Karashchenko <
petro.karashche...@gmail.com> wrote:
> Hi,
>
> This comes more to the edge of coding language paradigms, personal
> preferences and readability.
> For enable in Rust everything that you define is "const" and if you want
Hi,
This comes more to the edge of coding language paradigms, personal
preferences and readability.
For enable in Rust everything that you define is "const" and if you want to
modify it you should explicitly specify it. On another hand in C everything
you define is modifiable unless you specify "c
On 2024-07-11 23:36:22, Saurav Pal wrote:
> Hi all,
>
> Suppose I have a pointer that I want to pass through function parameters.
> In the function, neither is the pointer reassigned, nor is the thing it
> points to modified in any form.
>
> So, I would assume its function argument signature to b
Hi Saurav,
I think it comes down to whether a parameter like "const uint8_t * const"
is C89-compatible. I can't seem to find a reference that gives me a
definitive answer to this question, but it *might* have originally been a
C++ feature that became standard C at some point. Whether that happened
Hi Alan,
Thank you for the information. However, for my case, it's passed through
function parameters.
For example, let's say it's a helper function to read mem[2]. `mem` in this
case is a function argument. It isn't reassigned, so the pointer is a
const, and it isn't used to modify the underlyin
Hi Saurav,
I don't know why it is not much used, maybe Greg or Xiang have some idea.
I think the most common use of const for variables that you want to keep in
flash to avoid keeping it in RAM (to save RAM space for MCU with low RAM
memory).
The side effect on this case is Flash access is slowe
Hi all,
Suppose I have a pointer that I want to pass through function parameters.
In the function, neither is the pointer reassigned, nor is the thing it
points to modified in any form.
So, I would assume its function argument signature to be like FAR const
struct my_struct * const ptr (The secon
11 matches
Mail list logo