You are not logged in.

#1 2014-05-27 20:24:17

publicus
Member
Registered: 2014-01-01
Posts: 129

[RESOLVED] warning: initialization from incompatible pointer type

Hello,

I've been following this tutorial about linux drivers:
www.freesoftwaremagazine.com/articles/drivers_linux

Now, when I compile the code, this is what I get (the warnings on lines 117 and 137 don't concern me):

$ make -C /usr/src/kernels/2.6.32-431.11.2.el6.x86_64/ M=`pwd` modules
make: Entering directory `/usr/src/kernels/2.6.32-431.11.2.el6.x86_64'
  CC [M]  ~/Documents/development/drivers/code_003/memory.o
~/Documents/development/drivers/code_003/memory.c:36: warning: initialization from incompatible pointer type
~/Documents/development/drivers/code_003/memory.c: In function ‘memory_read’:
~/Documents/development/drivers/code_003/memory.c:117: warning: unused variable ‘result’
~/Documents/development/drivers/code_003/memory.c: In function ‘memory_write’:
~/Documents/development/drivers/code_003/memory.c:137: warning: ISO C90 forbids mixed declarations and code
~/Documents/development/drivers/code_003/memory.c:137: warning: unused variable ‘result’
  Building modules, stage 2.
  MODPOST 1 modules
  CC      ~/Documents/development/drivers/code_003/memory.mod.o
  LD [M]  ~/Documents/development/drivers/code_003/memory.ko.unsigned
  NO SIGN [M] ~/Documents/development/drivers/code_003/memory.ko
make: Leaving directory `/usr/src/kernels/2.6.32-431.11.2.el6.x86_64'

Here is the source:
https://gist.github.com/anonymous/ff515ebb2f54e267ea69

Why am I getting that first warning?  And what's with the structure using colons?

Last edited by publicus (2014-05-28 14:43:29)

Offline

#2 2014-05-27 20:44:21

Trilby
Forum Moderator
From: Massachusetts, USA
Registered: 2011-11-29
Posts: 14,207
Website

Re: [RESOLVED] warning: initialization from incompatible pointer type

The colons are for bit field assignment.

The warning is likely due to your function not matching the type that is expected - though I'm not sure why yet, your code matches the tutorial.

But are you really using kernel2.6?

Last edited by Trilby (2014-05-27 20:57:25)


InterrobangSlider
• How's my coding? See this page.
• How's my moderating? Feel free to email any concerns, complaints, or objections.

Offline

#3 2014-05-27 20:59:51

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 13,432

Re: [RESOLVED] warning: initialization from incompatible pointer type

publicus wrote:

And what's with the structure using colons?

https://stackoverflow.com/questions/856 … es-it-mean

tl;dr  It gives you the ability to control the packing of things in the structure down to the bit level.   Often computer registers use a single word broken into bit fields.  The colons tell the compiler how to pack the fields in a very specific way rather than giving the compiler carte blanche.

Edit: Snaked by Trilby. Again.

Last edited by ewaller (2014-05-27 21:00:29)


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
You assume people are rational and influenced by evidence.  You must not work with the public much. -- Trilby
----
How to Ask Questions the Smart Way

Offline

#4 2014-05-27 21:04:11

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 13,432

Re: [RESOLVED] warning: initialization from incompatible pointer type

Actually Trilby, we are both wrong.   Look at answer three in the site I linked.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
You assume people are rational and influenced by evidence.  You must not work with the public much. -- Trilby
----
How to Ask Questions the Smart Way

Offline

#5 2014-05-27 21:04:55

Trilby
Forum Moderator
From: Massachusetts, USA
Registered: 2011-11-29
Posts: 14,207
Website

Re: [RESOLVED] warning: initialization from incompatible pointer type

I just noticed that - Learn something new every day.


InterrobangSlider
• How's my coding? See this page.
• How's my moderating? Feel free to email any concerns, complaints, or objections.

Offline

#6 2014-05-27 21:12:30

publicus
Member
Registered: 2014-01-01
Posts: 129

Re: [RESOLVED] warning: initialization from incompatible pointer type

Trilby wrote:

The colons are for bit field assignment.

The warning is likely due to your function not matching the type that is expected - though I'm not sure why yet, your code matches the tutorial.

But are you really using kernel2.6?

This is on a different machine, so, yes, 2.6.

Offline

#7 2014-05-27 21:18:10

publicus
Member
Registered: 2014-01-01
Posts: 129

Re: [RESOLVED] warning: initialization from incompatible pointer type

ewaller wrote:
publicus wrote:

And what's with the structure using colons?

https://stackoverflow.com/questions/856 … es-it-mean

tl;dr  It gives you the ability to control the packing of things in the structure down to the bit level.   Often computer registers use a single word broken into bit fields.  The colons tell the compiler how to pack the fields in a very specific way rather than giving the compiler carte blanche.

Edit: Snaked by Trilby. Again.

Thanks.

How weird.  GCC is still complaining about it.  I still don't understand exactly why this is happening (but then, I know little about writing driver specific code *shrug*.)  I'll make a note of this and come back to it.

[edit]

I don't think I can get more out of this thread.  Marking it resolved for now.

Last edited by publicus (2014-05-28 14:43:18)

Offline

Board footer

Powered by FluxBB