What is the significance of caddr_t and when is it used?

22,108

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 *.

Share:
22,108
RajSanpui
Author by

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, 2022

Comments

  • RajSanpui
    RajSanpui almost 2 years

    Can somebody please tell me:

    1. What is caddr_t ?
    2. When is it used ?
    3. How it is different from void* ?
    4. When to use void* and when to use caddr_t ?

    Thanks in advance.

  • RajSanpui
    RajSanpui almost 13 years
    You 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
    R.. GitHub STOP HELPING ICE almost 13 years
    It 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
    RajSanpui almost 13 years
    Thank 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
    R.. GitHub STOP HELPING ICE almost 13 years
    Simply look at POSIX which does not mention caddr_t anywhere. In particular, the documentation for mmap: pubs.opengroup.org/onlinepubs/9699919799/functions/mmap.html has the correct prototype with void *. You can search the rest of the standard for caddr_t if you like but you won't find it because it doesn't exist.
  • Admin
    Admin almost 13 years
    I 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
    R.. GitHub STOP HELPING ICE almost 13 years
    Linux kernel is not a good reference for sane use of types... :-)
  • RajSanpui
    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 to efence code.
  • R.. GitHub STOP HELPING ICE
    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 for mmap (and perhaps certain other functions like brk) in place of void *. This usage is not reflected in modern standards or operating systems. What more do you want me to say?
  • RajSanpui
    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
    Admin almost 13 years
  • RajSanpui
    RajSanpui almost 13 years
    @pst: That's what i was trying to do :)
  • chacham15
    chacham15 about 12 years
    just as a side note, the linux kernel isnt the only place. I just found it as an argument to osx's ptrace function.