News for hackers. Stuff that matters.
Re:Typedefs & Linus by ori_b on Thursday October 14, 2010 @10:33AM (#1790996)
Sorry, what?

    $ cat test.c
    int x;
    unsigned long addr_t = &x;

    $ cc  test.c
    test.c:2: warning: initialization makes integer from pointer without a cast
Re:Typedefs & Linus by scott_s on Thursday October 14, 2010 @11:07AM (#1791137)
He's correct that it's legal ANSI C, but pvg is also correct in pointing out that compilers will warn you. (And being legal ANSI C is not necessarily the same thing as being portable.)
Re:Typedefs & Linus by Locke1689 on Thursday October 14, 2010 @12:47PM (#1791562)
Right but it's not about being portable in kernel development -- the entire thing you're building is in and of itself nonportable.
Re:Typedefs & Linus by scott_s on Thursday October 14, 2010 @02:10PM (#1791920)
Err, not really. You should be as portable as possible across different architectures. For example, on a 32-bit machine you can get away with using an unsigned int to represent an address, but that will break on a 64-bit machine.

The fact that the Linux kernel works on such disparate architectures also works against your point.

Re:Typedefs & Linus by Locke1689 on Thursday October 14, 2010 @03:19PM (#1792196)
No it's not portable C. We replicate code for different architectures. There are portable sections, true, but the entire kernel isn't portable. Look in the source directory to find the amd64/x86/ARM specific code.

If you know how to make

__asm__ __volatile__(...)

portable I'd love to hear it.

Re:Typedefs & Linus by scott_s on Thursday October 14, 2010 @03:38PM (#1792277)
We may be in violent agreement. Large swaths of the kernel can be portable, and you should code them as such. Of course architecture specific parts of the kernel will not be portable.
Re:Typedefs & Linus by Locke1689 on Thursday October 14, 2010 @06:24PM (#1792903)
Yeah I think you're right. :)
Re:Typedefs & Linus by ori_b on Thursday October 14, 2010 @02:00PM (#1791875)
It's legal, but taking the address and assigning directly to integers without a cast is anything but idiomatic.
Re:Typedefs & Linus by Locke1689 on Thursday October 14, 2010 @03:22PM (#1792213)
I just forgot the cast. It was really late (5am my time) when I wrote this post.