473,626 Members | 3,439 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

converting inline functions to C functions

Hello,
I would like to convert the following inline function to a macro. Can
someone help?

Thx
Jami

inline
char *
fromDESC(const char * &aDesC)
{
char * res;
INT32 ix;
res = PSTRnewL(STRlen gth(aDesC));
// copy string
for (ix = STRlength(aDesC ); ix; ix--, res[ix] = aDesC[ix]);
return(res);
}

May 16 '06 #1
7 1958


jamihuq wrote On 05/16/06 11:35,:
Hello,
I would like to convert the following inline function to a macro. Can
someone help?

Thx
Jami

inline
char *
fromDESC(const char * &aDesC)
{
char * res;
INT32 ix;
res = PSTRnewL(STRlen gth(aDesC));
// copy string
for (ix = STRlength(aDesC ); ix; ix--, res[ix] = aDesC[ix]);
return(res);
}


#define fromDESC(x) -()-

will have the same effect for C, namely, to cause the
compiler to emit a diagnostic.

As an aside, it may interest you to know that there
is a newsgroup called comp.lang.c++ devoted to That
Other Language. Follow-ups set.

--
Er*********@sun .com

May 16 '06 #2
jamihuq posted:
Hello,
I would like to convert the following inline function to a macro. Can
someone help?

A retarded six year old, who had three quarters of their brain removed with
a rusty garden sheers, can comprehend that macros just replace text.

What, oh what, is stopping you from typing it out yourself?

Furthermore, why, oh why, would you want to turn an inline function into a
horrible macro?

Do you realise that the C++ code you have presented is absolute dirt? It was
obviously written by a very poor novice. There was no reason to pass the
char pointer by reference. First thing I'll do is make the C++ code a bit
more respectable:

#include <cstring>
#include <cstddef>
#include <cstdlib>

inline char * const fromDESC(const char * const aDesC)
{
using std::size_t;
using std::strlen;
using std::memcpy;

size_t const buf_length = strlen(aDesC) + 1;

char * const res = new char[buf_length];

memcpy( res, aDesC, buf_length );

return res;
}

Now I'll turn that into C:

#include <string.h>
#include <stddef.h>
#include <stdlib.h>

inline char * const fromDESC(const char * const aDesC)
{
size_t const buf_length = strlen(aDesC) + 1;

char * const res = malloc(buf_leng th);

memcpy( res, aDesC, buf_length );

return res;
}
Now you have a C function which works exactly like the wreckage of a C++
function which you originally presented.
-Tomás
May 16 '06 #3
Tomás wrote:

<snip>
Do you realise that the C++ code you have presented is absolute dirt? It was
obviously written by a very poor novice. There was no reason to pass the
char pointer by reference. First thing I'll do is make the C++ code a bit
more respectable:


<snip>

Tomas, you do realise that there is a separate group for C++? It's down
the hall third door on the right called, strangely enough, comp.lang.c++

I realise you were just replying, but you should have taken it to the
correct group rather than posting a long post about C++ in a C group.
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc
May 16 '06 #4
Man, that was uber harsh.

May 16 '06 #5
Tomás wrote:
#include <string.h> #include <stdlib.h>

inline char * const fromDESC(const char * const aDesC)
{
size_t const buf_length = strlen(aDesC) + 1;

char * const res = malloc(buf_leng th);

if (res != NULL) {
memcpy( res, aDesC, buf_length );
}

return res;
}


--
pete
May 16 '06 #6
jamihuq wrote:

Man, that was uber harsh.


Totally meaningless post. In general on usenet you should realize
that readers may very well not have convenient access to previous
articles in a thread. That means that your reply articles should
include adequate context, so that they stand by themselves. Google
is NOT usenet, it is only a very poor interface to the real usenet
system. To include proper context when using google, see my sig.
below. Please be sure to read the referenced URLs.

--
"If you want to post a followup via groups.google.c om, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell. org/google/>
Also see <http://www.safalra.com/special/googlegroupsrep ly/>

May 17 '06 #7
Tomás wrote:
jamihuq posted:
Hello,
I would like to convert the following inline function to a macro. Can
someone help?


<snip>
Furthermore, why, oh why, would you want to turn an inline function
into a horrible macro?


<snip>

Perhaps to guarantee that it *is* 'inlined' - after all, as long as the
compiler recognises the keyword, it's free to ignore it.

--
==============
Not a pedant
==============
May 17 '06 #8

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

Similar topics

13
6548
by: A | last post by:
Hi, I'm having problems completing a project in C++. I have been using inline functions in some of my header files. I have only done so for simple functions that only have 1 statement (eg. accessor and mutator methods to access private data members). I would like to know if there are any issues with using inline functions that may have attributed to my errors before I start separting them out into "outline functions". Regards
14
2770
by: Chris Mantoulidis | last post by:
I am not clear with the use of the keyword inline... I believe you add it do a function when you implement the function inside the header file where the class is stored... But is that all? What am I missing? If that's all, then why did Bjarne even bother adding it to the language? If that's not all, what else can I do with "inline"?
47
3848
by: Richard Hayden | last post by:
Hi, I have the following code: /******************************** file1.c #include <iostream> extern void dummy(); inline int testfunc() {
21
746
by: Rubén Campos | last post by:
I haven't found any previous message related to what I'm going to ask here, but accept my anticipated excuses if I'm wrong. I want to ask about the real usefulness of the 'inline' keyword. I've read many authors (and it's my belief, too) who discourage the use of the 'inline' keyword, because: - The 'inline' word only advice the compiler about wich functions should be expanded, but not force it to expand them. Also, the compiler can...
7
2855
by: Srini | last post by:
Hello, Rules for inline functions say that they have to be defined in the same compilation unit as their declarations. For class member functions this means that the inline member functions must be defined either within the class or within the same header file. But its generally a good programming practice to have the declarations and definitions in seperate files. This would make the future maintenance of the code easier.
4
1813
by: Tony Johansson | last post by:
Hello experts! I'm reading a book about C++ and there is something about inline that the book says that is unclear for me. The book says the following "Because inline functions are expanded at compile time, definitions of these functions, unlike other definitions, cannot be separately compiled and must be placed in header files. This creates a problem if the compiler does not actually inline a
43
13268
by: Patrick Laurent | last post by:
Hello I have a program with many many inlined template functions It is essential for the execution speed that every (or almost every) function marked as inlined, becomes really inlined by the compiler. I already compiled the program with Intel Compiler (ICL) on Visual C++, and it works fine and fast. I verified that the functions are really inlined. But with GCC 3.4 (Linux+Cygwin) or ICC (Linux), The same program is about 5
18
5047
by: Method Man | last post by:
If I don't care about the size of my executable or compile time, is there any reason why I wouldn't want to inline every function in my code to make the program run more efficient?
2
3996
by: CoreyWhite | last post by:
Problem: You have numbers in string format, but you need to convert them to a numeric type, such as an int or float. Solution: You can do this with the standard library functions. The functions strtol, strtod, and strtoul, defined in <cstdlib>, convert a null- terminated character string to a long int, double, or unsigned long. You can use them to convert numeric strings of any base to a numeric
0
8202
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,...
0
8707
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8366
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
8510
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
7199
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
5575
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
4093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4202
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1812
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.