By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,804 Members | 1,666 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,804 IT Pros & Developers. It's quick & easy.

Could you explain

100+
P: 158
I have this bit of code and im not used to C and it would help if some one could explain it in lamence terms.

Expand|Select|Wrap|Line Numbers
  1. typedef struct {
  2.     uchar IP[4];    // IP address
  3.     ushort Port;    // UDP port    BYTE-SWAPPED MANUALLY
  4. } T_Addr;
  5.  
Jun 1 '07 #1
Share this Question
Share on Google+
18 Replies


RedSon
Expert 5K+
P: 5,000
I have this bit of code and im not used to C and it would help if some one could explain it in lamence terms.

Expand|Select|Wrap|Line Numbers
  1. typedef struct {
  2.     uchar IP[4];    // IP address
  3.     ushort Port;    // UDP port    BYTE-SWAPPED MANUALLY
  4. } T_Addr;
  5.  
First is laymans terms. Or to be more politically correct its just lay terms.

This code declares a struct named T_Addr which has a 4 element array of uchars called IP and a ushort called Port.

In an even broader view it looks like its a struct that houses a ip address and port number to make connections with.
Jun 1 '07 #2

AdrianH
Expert 100+
P: 1,251
First is laymans terms. Or to be more politically correct its just lay terms.
What? Not layperson's terms? ;D


Adrian
Jun 1 '07 #3

100+
P: 158
I get that all but another part of my code declares the ushort and uchar,
Expand|Select|Wrap|Line Numbers
  1. #define uchar unsigned char
  2. #define ushort unsigned short int
but one thing i am not getting is what is uchar and ushort is it a variable or what and what its relation ship to IP when its called in the struct.
Jun 1 '07 #4

ilikepython
Expert 100+
P: 844
I get that all but another part of my code declares the ushort and uchar,
Expand|Select|Wrap|Line Numbers
  1. #define uchar unsigned char
  2. #define ushort unsigned short int
but one thing i am not getting is what is uchar and ushort is it a variable or what and what its relation ship to IP when its called in the struct.
With the defines, uchar is a synonym for unsigned char and ushort is a synonym for unsigned short int. So basically, IP is an array of 4 unsigned chars
Jun 1 '07 #5

100+
P: 158
so it is saying uchar = unassigned char which are both varibles?
Jun 1 '07 #6

100+
P: 208
so it is saying uchar = unassigned char which are both varibles?
uchar IP[4];
ushort Port;

The IP is an array of unsigned chars but the Port is an unsigned short int....

Also, its unsigned not unassigned (meaning it can't be negative...not that it just doesn't have a value.

As to using this struct you would call it as such:

T_Addr.IP[0] = 'A';
T_Addr.Port = 123
Jun 1 '07 #7

ilikepython
Expert 100+
P: 844
so it is saying uchar = unassigned char which are both varibles?
Sort of...
#define <first> <second>

Define replaces every occurance of first with second. It doesn't know anything about C or C++. It just edits the source file before compilation. So everytime there is the sequence of letters "uchar" the preprocessor will replace it with "unsigned char" so the compiler understands it.
Jun 1 '07 #8

100+
P: 158
ok i kinda get that, but off topic, is there a way in PERL programing if some one knows to do the same type of thing.
Jun 1 '07 #9

AdrianH
Expert 100+
P: 1,251
ok i kinda get that, but off topic, is there a way in PERL programing if some one knows to do the same type of thing.
Maybe, don't know off hand. Try asking that in the Perl forum.


Adrian
Jun 1 '07 #10

RedSon
Expert 5K+
P: 5,000
ok i kinda get that, but off topic, is there a way in PERL programing if some one knows to do the same type of thing.
Look I'm pretty sure you already asked this question and I forwarded it to the PERL forum. If you want to learn about PERL why dont you start posting there? Lots of PERL guys are also C/C++ gurus.
Jun 1 '07 #11

RedSon
Expert 5K+
P: 5,000
Look I'm pretty sure you already asked this question and I forwarded it to the PERL forum. If you want to learn about PERL why dont you start posting there? Lots of PERL guys are also C/C++ gurus.
Yep I was right

http://www.thescripts.com/forum/thread655570.html
Jun 1 '07 #12

RedSon
Expert 5K+
P: 5,000
Lets try to keep the related threads all in one place okay? I don't want to see more "what does this mean in C++" and then a post 4-5 replies later going "now can you translate that into PERL"
Jun 1 '07 #13

100+
P: 158
ok sorry that was not my intension.
Jun 1 '07 #14

RedSon
Expert 5K+
P: 5,000
ok sorry that was not my intension.
Ok but if you have PERL questions use the perl forum. Thats what its there for. We encourage our users to post to the proper forum. And to not double post across forums.
Jun 1 '07 #15

DeMan
100+
P: 1,806
What? Not layperson's terms? ;D
I guess it's not politically correct to assume people/person..... :)
Jun 1 '07 #16

RedSon
Expert 5K+
P: 5,000
I guess it's not politically correct to assume people/person..... :)
Yea you wouldn't want to offend any non humanoid species now would you?
Jun 1 '07 #17

100+
P: 208
What? Not layperson's terms? ;D
I guess it's not politically correct to assume people/person..... :)
Would layit work? That way you're not really offending anyone.


PS....ooooo quotes inside of quotes...doesn't work out as nicely as I would have hoped.
Jun 4 '07 #18

AdrianH
Expert 100+
P: 1,251
Would layit work? That way you're not really offending anyone.
Dunno, some people don't like being called "it". ;)


PS....ooooo quotes inside of quotes...doesn't work out as nicely as I would have hoped.
Make a comment about it in the Feedback, Bugs, Suggestions Discussions forum.


Adrian
Jun 4 '07 #19

Post your reply

Sign in to post your reply or Sign up for a free account.