Variable and pointer

Discussion in 'C Programming' started by Julia, Jun 25, 2003.

  1. Julia

    Julia Guest

    I am a n00b to c, so have pitty on me if I ask dumb questions :).
    I have a function (testframe() ) that has needs a pointer to a 6 byte MAC
    address as input. The input is an unsigned 8 bit char pointer.
    This pointer should then point to the 6 byte MAC address stored somewhere.
    How do I actually write this in code? An integer is only 32 bit, so how do I
    have something holding the MAC Address and more again, how do I create a
    pointer pointing to this "something".

    Julia
     
    Julia, Jun 25, 2003
    #1
    1. Advertisements

  2. Julia

    Dan Pop Guest

    unsigned char macaddr[6], *p = macaddr;

    Dan
     
    Dan Pop, Jun 25, 2003
    #2
    1. Advertisements

  3. Julia

    Kevin Easton Guest

    unsigned char mac[6] = { 0x00, 0xC0, 0x4F, 0xDD, 0xB8, 0x73 };

    then just pass "mac". An array (like "mac") is evaluated as a pointer
    to its first subobject unless it is the operand of unary-& or sizeof, so
    you don't need to do anything special to create the pointer.

    - Kevin.
     
    Kevin Easton, Jun 25, 2003
    #3
  4. Most applications treat MAC addresses as a collection of
    octects (bytes). Just access it via pointer to unsigned
    char. If the processor wants to promote the 8-bit u.c.
    to a 32-bit unsigned integer, let it. Some processors
    actually fetch the 8 bits into a 32-bit register.

    If you need more help, please post a code fragment
    demonstrating what you are doing.
     
    Thomas Matthews, Jun 25, 2003
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.