Re: error in a compiling simple character device driver

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

 



Hi Alison,

On Thu, Sep 23, 2010 at 1:05 PM, Alison Chaiken <alchaiken@xxxxxxxxx> wrote:
> Manoj Gupta <manoj334@xxxxxxxxx> wrote:
>> Change
>> char *memory_buffer[];
>> to
>> char *memory_buffer;
>
> sri <bskmohan@xxxxxxxxx> wrote:
>>  But can you explain why that change worked?
>
> The change works because kmalloc returns the address of allocated
> memory that is pointer to a character array rather than returning a
> character array.    In general functions return pointers to arrays,
> which are not typically passed by value in C.

Actually, char *memory_buffer[] is an array of character pointers.
char *memory_buffer is a pointer to a character, which is also
compatabile with an array of characters.

> But what the heck does "error: 'memory_buffer' has an incomplete type"
> mean anyway?

No size was specified, so the compiler has no way of knowing how big
memory_buffer is.

>  I'm always puzzled by that error message, and I am a
> native English speaker!    Experience has shown that "has an
> incomplete type" does mean incorrect assignment to a pointer, but I
> can't guess what an "incomplete type" is!

In C, you're allowed to do stuff like this (say in a header file):

struct foo;
void func( struct foo *p );

Now, in the example above, struct foo is an incomplete type. I haven't
told you anything about it, other than its name. Since pointers to all
types of objects are the same size, the compiler knows exactly how big
the parameter is even if it doesn't know the size of the structure.

Of course, by the time you actually compile the source for 'func',
struct foo can no longer be incomplete.

-- 
Dave Hylands
Shuswap, BC, Canada
http://www.DaveHylands.com/

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ




[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux