C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 06-10-2009, 04:26 AM   #1
Registered User
 
Join Date: Jun 2009
Posts: 31
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
Dedalus is offline   Reply With Quote
Old 06-10-2009, 04:32 AM   #2
Deathray Engineer
 
MacGyver's Avatar
 
Join Date: Mar 2007
Posts: 3,211
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.
MacGyver is offline   Reply With Quote
Old 06-10-2009, 04:34 AM   #3
Registered User
 
Join Date: Jun 2009
Posts: 31
Thanks MacGyver
Dedalus is offline   Reply With Quote
Reply

Tags
pointer, struct

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Imposing Line Numbers automatically in the C code cavestine C Programming 14 10-15-2007 12:41 AM
help again with scrolling without wrapping Dukefrukem C Programming 8 09-21-2007 12:48 PM
How to do encryption in C sankarv C Programming 31 09-21-2006 05:37 AM
Quick question about SIGSEGV Cikotic C Programming 30 07-01-2004 07:48 PM
Request for comments Prelude A Brief History of Cprogramming.com 15 01-02-2004 10:33 AM


All times are GMT -6. The time now is 12:00 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22