restrictness of strtoi(3bsd) and strtol(3)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I've been implementing my own copy of strto[iu](3bsd), to avoid the
complexity of calling strtol(3) et al.  In the process, I've noticed
that all of these functions use restrict for their parameters.

Why do these functions use restrict?  While the second parameter is not
used for accessing nptr memory (**endptr is not accessed), it can point
to the same memory.  Here is an example of how these functions can have
pointers to the same memory in the two arguments.

	l = strtol(p, &p, 0);

The use of restrict in the prototype of the function could result in
compiler warnings, no?  Currently, I don't see any warnings, but I
suspect the compiler could complain, since the same memory is available
to the function via two different arguments (albeit with a different
number of references).

The use of restrict in the definition of the function doesn't help the
optimizer, since it already knows that the second parameter is out-only,
so even if it weren't restrict, the only way to access memory is via the
first parameter.

Thanks,
Alex

-- 
<https://www.alejandro-colomar.es/>

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux