Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   Variable and pointer (http://www.velocityreviews.com/forums/t313812-variable-and-pointer.html)

Julia 06-25-2003 01:09 PM

Variable and pointer
 
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



Dan Pop 06-25-2003 01:24 PM

Re: Variable and pointer
 
In <bdc6sk$quo$1@news.net.uni-c.dk> "Julia" <Julia_Hansen@hotmail.com> writes:

>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".


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

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Dan.Pop@ifh.de

Kevin Easton 06-25-2003 01:39 PM

Re: Variable and pointer
 
Julia <Julia_Hansen@hotmail.com> wrote:
> 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".


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.


Thomas Matthews 06-25-2003 01:53 PM

Re: Variable and pointer
 
Julia wrote:
> 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
>
>


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

Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:



All times are GMT. The time now is 09:27 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.