[lkml]   [2004]   [Feb]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
    SubjectRe: &array considered harmful?
    On Mon, 23 Feb 2004, Robert T. Johnson wrote:

    > The kernel has lots of code that takes the address of a local array.
    > This works, but it's fragile. I'd be happy to submit a patch if
    > everyone agrees that this is a bad programming practice.
    > Here's an example of a program that takes the address of an array:
    > void func(void)
    > {
    > char A[10];
    > ....
    > memset(&A, 0, sizeof(A));
    > }

    You are preaching to the choir when it comes to code like that.
    However, even lint allows it! I first thought it was a GNUism
    just like void-pointer math being allowed. But, when Lint says
    it's okay, I don't think there is any technical reason for
    not allowing it because Lint is the most pedantic of pedantica.

    Script started on Tue Feb 24 07:46:23 2004
    # cat xxx.c
    #include <stdio.h>
    int main(void);
    int main()
    char foo[0x10];
    printf("%p\n", foo);
    printf("%p\n", &foo[0]);
    printf("%p\n", &foo);
    return 0;
    # gcc -Wall --pedantic -o xxx xxx.c
    # lint xxx.c
    LCLint 2.2a --- 04 Sep 96
    Finished LCLint checking --- no code errors found
    # exit
    Script done on Tue Feb 24 07:47:03 2004

    Dick Johnson
    Penguin : Linux version 2.4.24 on an i686 machine (797.90 BogoMips).
    Note 96.31% of all statistics are fiction.

    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to
    More majordomo info at
    Please read the FAQ at

     \ /
      Last update: 2005-03-22 14:01    [W:0.022 / U:13.908 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site