What is the significance of caddr_t and when is it used?
Solution 1
caddr_t
is a legacy BSD type associated with some low level calls like mmap
, and it should never be used in modern code. It was rejected by the POSIX standard. The standardized mmap
uses void *
.
Solution 2
caddr_t
was used as a pointer to a core address. I used it in SVR4 when I needed to access kernel structures from user space (having used mmap to access /dev/kmem
). Even when "/proc
" existed, the ps command still used mmap of the kernel to start walking the process table. As everybody states it was superseded by void *.
RajSanpui
Around 9+ years experience into development C, C++, and Linux domain. Also understand Core-Java and consider it as a secondary skill. Currently, in addition to the developer responsibilities, i am also serving the role of DevOps engineer.
Updated on July 14, 2022Comments
-
RajSanpui almost 2 years
Can somebody please tell me:
- What is
caddr_t
? - When is it used ?
- How it is different from
void*
? - When to use
void*
and when to usecaddr_t
?
Thanks in advance.
- What is
-
RajSanpui almost 13 yearsYou said: "caddr_t is a legacy BSD type associated with some low level calls like mmap", you have slipped to mention the reason for it's association, when simultaneously
void*
also existed. -
R.. GitHub STOP HELPING ICE almost 13 yearsIt was probably created before
void *
existed, though I don't have a reference for that claim. In any case it's irrelevant now. It's not part of any modern standard, should not be used in new code, and should be fixed in old code. -
RajSanpui almost 13 yearsThank you for the answer. I understand your point, but can you please post a link/reference which says: "caddr_t is obsolete and instead void* must be used" ?
-
R.. GitHub STOP HELPING ICE almost 13 yearsSimply look at POSIX which does not mention
caddr_t
anywhere. In particular, the documentation formmap
: pubs.opengroup.org/onlinepubs/9699919799/functions/mmap.html has the correct prototype withvoid *
. You can search the rest of the standard forcaddr_t
if you like but you won't find it because it doesn't exist. -
Admin almost 13 yearsI second that. While perhaps not in the POSIX
mmap
signature, it is used a good bit in the Linux kernel. (I understand this is a "specific domain", but...) -
R.. GitHub STOP HELPING ICE almost 13 yearsLinux kernel is not a good reference for sane use of types... :-)
-
RajSanpui almost 13 years@R..: I am sorry, but do you think not having mentioned in POSIX man for an API
mmap
, mean that it is obsolete???? Infact i saw that man page prior to posting my query. If it is obsolete it must be mentioned somewhere...and the fact is i am unable to google it to get a proof. please refer toefence
code. -
R.. GitHub STOP HELPING ICE almost 13 years@kingsmasher1: Are you trying to get an answer or are you trying to start an argument? The classic place
caddr_t
was used was as an argument and return type formmap
(and perhaps certain other functions likebrk
) in place ofvoid *
. This usage is not reflected in modern standards or operating systems. What more do you want me to say? -
RajSanpui almost 13 years@R: It's not about arguing 'R', the place where we guys work, requires substantial proof and supporting docs, before we utter a word, or write a single line of code, and one faulty code going in the products costs much and we ought to be more careful because we write code for embeddded systems and real-time systems for CE-Linux and it's not x86 but ARM. So we have to be very careful.
-
Admin almost 13 years@kingsmasher1 When in Rome, do as the Romans do...
-
RajSanpui almost 13 years@pst: That's what i was trying to do :)
-
chacham15 about 12 yearsjust as a side note, the linux kernel isnt the only place. I just found it as an argument to osx's
ptrace
function.