473,748 Members | 2,567 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(nam e, octets) p->name = -1; Is it define a
function
TLV_INTEGER(nam e, 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_numbe r = 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(nam e, octets) p->name = -1;
#define TLV_NULTERMINAT ED(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(n ame, max_octets) p->name = NULL;
#define OCTETS(name, field_giving_oc tetst) 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_numbe r = seq_no; \
} break;
default:
error(0, "Unknown SMPP_PDU type, internal error.");
gw_free(pdu);
return NULL;
}
Mar 14 '08 #1
3 2046
qi*****@gmail.c om 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(nam e, octets) p->name = -1; Is it define a
function
TLV_INTEGER(nam e, 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_numbe r = 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.c om 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(nam e, octets) p->name = -1; Is it define a
function
TLV_INTEGER(nam e, 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_numbe r = 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.c om 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.htm l>
<http://cfaj.freeshell. org/google/ (taming google)
<http://members.fortune city.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
19114
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 any preconceived ideas about it. I have noticed, however, that every programmer I talk to who's aware of Python is also talking about Ruby. So it seems that Ruby has the potential to compete with and displace Python. I'm curious on what basis it...
699
34068
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 capabilities, unfortunately. I'd like to know if it may be possible to add a powerful macro system to Python, while keeping its amazing syntax, and if it could be possible to add Pythonistic syntax to Lisp or Scheme, while keeping all of the...
3
3002
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 waste of time to start writing yet another IDE and so am now thinking in terms of new features/plug-ins for existing systems. Right now I mostly use Komodo Personal and it's pretty close to being what I want. They don't currently support plug-ins,...
92
6510
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? cheers, reed
3
1561
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 # mark
125
14809
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 software giant such as Microsoft SQL Server, Oracle, and Sybase? Is PostgreSQL reliable enough to be used for high-end commercial application? Thanks
44
4262
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 must be many know the answer here. thanks
35
3340
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 it as good as a programming language can get? Like so many of you, I programmed speech recognizers, image recognition systems, a portion of a chess program, lots of numeric code using STL, and tons of other applications in C++, (even firmware...
121
10131
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 support IDEs are DreamWeaver 8 and Zend PHP Studio. DreamWeaver provides full support for Unicode. However, DreamWeaver is a web editor rather than a PHP IDE. It only supports basic IntelliSense (or code completion) and doesn't have anything...
13
5053
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
0
8996
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8832
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9333
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8255
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3319
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.