Thread: C code line, pointer declaration

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    56

    Post C code line, pointer declaration

    Hi

    I don't understand this code line:
    Code:
    struct iphdr *iph=(struct iphdr *)data;
    where data is an u_char.
    What I can see is that we are creating a pointer (iph) to a iphdr struct, but the right side is not very clear. Can anyone explain the meaning, please?

    Thanks in advance

    Dedalus

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    If this example is too difficult to understand, you should get a good C book and learn the basics. The code is casting data to a struct iphdr * and then assigning it to the newly created variable iph.

    BTW, if you mean that data is an unsigned char, then this cast is rather horrible to do and makes little sense to me. In fact, this could be the cause of some ugly problems.

    Oh, and welcome to cboard.
    Last edited by MacGyver; 06-10-2009 at 04:37 AM. Reason: Messed up spelling of type name.

  3. #3
    Registered User
    Join Date
    Jun 2009
    Posts
    56
    Thanks MacGyver

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to do encryption in C
    By sankarv in forum C Programming
    Replies: 33
    Last Post: 12-28-2010, 11:01 AM
  2. Imposing Line Numbers automatically in the C code
    By cavestine in forum C Programming
    Replies: 14
    Last Post: 10-15-2007, 12:41 AM
  3. help again with scrolling without wrapping
    By Dukefrukem in forum C Programming
    Replies: 8
    Last Post: 09-21-2007, 12:48 PM
  4. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM

Tags for this Thread