Re: How to retrieve data from array of pointers or from a struct?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ulrich Eckhardt

    #1

    Re: How to retrieve data from array of pointers or from a struct?

    Victor wrote:
    I have 2 problems:
    Start two threads, at least in general.
    unsigned long long i;
    >
    unsigned long long *dataPatternPtr[] = {
    This defines an array of pointers to unsigned long longs...
    0xa0a0000000000 0aaLL,
    0xFFFFFFFFFFFFF FFFLL,
    0x5555555555555 555LL,
    0xAAAAAAAAAAAAA AAALL,
    0xCCCCCCCCCCCCC CCCLL,
    0x3333333333333 333LL,
    0xEEEEEEEEEEEEE EEELL,
    0x7777777777777 777LL,
    0x0000000000000 001LL,
    0xFFFFFFFFFFFFF FFELL,
    0xABCDEF0123456 789LL,
    };
    ....while initialising the pointers with long long values. Is that intended?
    I guess not, because typically you don't hardcode addresses except in
    low-level driver code. Further, do you intend to modify this? If not, then
    make it const.
    unsigned long long seed = *(dataPatternPt r + 2); // This one
    works during compile
    This can also be written as ..= dataPatternPtr[2];
    However, it features a conversion between an "unsigned long long*" and
    an "unsigned long long". You should definitely crank up the warning level
    of your compiler, I'm sure it would have told you.
    unsigned long long seed = *(dataPatternPt r + i); // *********
    ERROR ****** But why does this one not work?
    In C89, all declarations of variables have to precede the code. Since 'i' is
    not a constant, you are mixing this here which is what the compiler
    complains about. Well, at least that's my guess, since you neither provided
    full code nor an error message.
    /projects/svdc/aurora.validati on/work/vhnguyen/aurora_validati on/uboot/
    examples/zzzmain.c:295: undefined reference to `memcpy'
    make[1]: *** [zzzmain] Error 1
    >
    Does anyone know why? It seems memcpy is not found in #include files
    but what library memcpy should reside in?
    #include only adds the necessary declaration, you still need to link the
    right libs. In particular with builtin things like memcpy(), this should be
    done automatically. Since you seem to be hacking a bootloader, this might
    not be completely the case though. Anyway, this is highly dependent on the
    actual compiler, so I'd ask questions about its use in a dedicated forum.

    Uli

  • Ben Bacarisse

    #2
    Re: How to retrieve data from array of pointers or from a struct?

    Ulrich Eckhardt <doomster@knuut .dewrites:
    Victor wrote:
    <snip>
    > unsigned long long seed = *(dataPatternPt r + i); // *********
    >ERROR ****** But why does this one not work?
    >
    In C89, all declarations of variables have to precede the code.
    In C89 // is a syntax error, so I doubt the OP is using C89 (aka C90).
    Since 'i' is
    not a constant, you are mixing this here which is what the compiler
    complains about.
    I don't see what is wrong with initialising a variable with a
    non-constant expression. I.e. the fact that i is or is not constant
    probably has nothing to do with your suspected source of the error.
    Anyway, you are quite correct that only full code (or, better, full
    code of a cut down example) can resolve this one:
    Well, at least that's my guess, since you neither provided
    full code nor an error message.
    <snip>

    --
    Ben.

    Comment

    Working...