473,385 Members | 1,338 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

what does this code do?

Hi I am not sure what this code does.
I have the following questions
1. where is the case?
2. #define TLV_INTEGER(name, octets) p->name = -1; Is it define a
function
TLV_INTEGER(name, octets) and return a -1? and similar questions on
other #define

3. in
#define PDU(name, id, fields) \
case id: { \
struct name *p = &pdu->u.name; \
pdu->type_name = #name; \
fields \
p->command_id = type; \
p->sequence_number = seq_no; \
} break;

Why do I need a '"\" and what does it mean by "#name"

Thank you very much!
switch (type) {
#define OPTIONAL_BEGIN
#define TLV_INTEGER(name, octets) p->name = -1;
#define TLV_NULTERMINATED(name, max_len) p->name = NULL;
#define TLV_OCTETS(name, min_len, max_len) p->name = NULL;
#define OPTIONAL_END
#define INTEGER(name, octets) p->name = 0;
#define NULTERMINATED(name, max_octets) p->name = NULL;
#define OCTETS(name, field_giving_octetst) p->name = NULL;
#define PDU(name, id, fields) \
case id: { \
struct name *p = &pdu->u.name; \
pdu->type_name = #name; \
fields \
p->command_id = type; \
p->sequence_number = seq_no; \
} break;
default:
error(0, "Unknown SMPP_PDU type, internal error.");
gw_free(pdu);
return NULL;
}
Mar 14 '08 #1
3 2006
qi*****@gmail.com wrote:
Hi I am not sure what this code does.
It switches on `type', goes to the default: label,
calls error() and gw_free(), and returns NULL from the
function that contains it.
I have the following questions
1. where is the case?
The only case in this switch statement is the default.
2. #define TLV_INTEGER(name, octets) p->name = -1; Is it define a
function
TLV_INTEGER(name, octets) and return a -1? and similar questions on
other #define
#define defines a preprocessor macro.
3. in
#define PDU(name, id, fields) \
case id: { \
struct name *p = &pdu->u.name; \
pdu->type_name = #name; \
fields \
p->command_id = type; \
p->sequence_number = seq_no; \
} break;

Why do I need a '"\" and what does it mean by "#name"
Each backslash-newline pair ends a line of source code
but does not end the macro definition (without the backslash,
the macro definition would end at the newline). So the body
of the PDU macro contains not only what's on the #define line
itself, but all of the following seven lines as well. The
definition ends after the eighth line because the newline
at the end of that line is not preceded by a backslash.

As for #name, see Question 11.18 in the comp.lang.c
Frequently Asked Questions (FAQ) list <http://www.c-faq.com/>.
[code snipped; see up-thread]
--
Er*********@sun.com
Mar 14 '08 #2
Thank you very much! I will find a preprocessor macro tutorial.
However, I'd like to ask another question.
If switch only goes to the default value, why there are so many
#define in front of the default value. Does it mean it goes to the
macros one by one?

Thank you very much!

Eric Sosman wrote:
qi*****@gmail.com wrote:
Hi I am not sure what this code does.

It switches on `type', goes to the default: label,
calls error() and gw_free(), and returns NULL from the
function that contains it.
I have the following questions
1. where is the case?

The only case in this switch statement is the default.
2. #define TLV_INTEGER(name, octets) p->name = -1; Is it define a
function
TLV_INTEGER(name, octets) and return a -1? and similar questions on
other #define

#define defines a preprocessor macro.
3. in
#define PDU(name, id, fields) \
case id: { \
struct name *p = &pdu->u.name; \
pdu->type_name = #name; \
fields \
p->command_id = type; \
p->sequence_number = seq_no; \
} break;

Why do I need a '"\" and what does it mean by "#name"

Each backslash-newline pair ends a line of source code
but does not end the macro definition (without the backslash,
the macro definition would end at the newline). So the body
of the PDU macro contains not only what's on the #define line
itself, but all of the following seven lines as well. The
definition ends after the eighth line because the newline
at the end of that line is not preceded by a backslash.

As for #name, see Question 11.18 in the comp.lang.c
Frequently Asked Questions (FAQ) list <http://www.c-faq.com/>.
[code snipped; see up-thread]

--
Er*********@sun.com
Mar 14 '08 #3
qi*****@gmail.com wrote:
>
Thank you very much! I will find a preprocessor macro tutorial.
However, I'd like to ask another question. If switch only goes to
the default value, why there are so many #define in front of the
default value. Does it mean it goes to the macros one by one?
Please do not top-post. Your answer belongs after (or intermixed
with) the quoted material to which you reply, after snipping all
irrelevant material. See the following links:

--
<http://www.catb.org/~esr/faqs/smart-questions.html>
<http://www.caliburn.nl/topposting.html>
<http://www.netmeister.org/news/learn2quote.html>
<http://cfaj.freeshell.org/google/ (taming google)
<http://members.fortunecity.com/nnqweb/ (newusers)
--
Posted via a free Usenet account from http://www.teranews.com

Mar 14 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
3
by: Chris Cioffi | last post by:
I started writing this list because I wanted to have definite points to base a comparison on and as the starting point of writing something myself. After looking around, I think it would be a...
92
by: Reed L. O'Brien | last post by:
I see rotor was removed for 2.4 and the docs say use an AES module provided separately... Is there a standard module that works alike or an AES module that works alike but with better encryption?...
3
by: mark | r | last post by:
is there an industry standard method of costing out a project the problem i have is that when talking to a developer they say "i dont know how long it will take" which just isnt acceptable #...
125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
44
by: lester | last post by:
a pre-beginner's question: what is the pros and cons of .net, compared to ++ I am wondering what can I get if I continue to learn C# after I have learned C --> C++ --> C# ?? I think there...
35
by: GTO | last post by:
I do not believe that C# is the future of C++. I also do not believe that adding two thousand new library functions to the standard library is the future of C++. But what is the future of C++? Is...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.