473,806 Members | 2,583 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

obj function hello()

#include <stdio.h>

obj function hello(){
struct obj = { char *data = 'hello'}
obj.add = obj_add(obj);
return obj;
}

void function obj_add(obj){
obj function add(value){
obj.data += value;
return obj;
}
}

void main(){
test = hello();
test.add('world ');
printf(test.dat a);
}

I don't know much c and i was hoping the code above was pointing out
what i am trying to do ?

Feb 9 '07
40 2318
On 9 Feb 2007 08:48:12 -0800, in comp.lang.c , "gert"
<ge**********@g mail.comwrote:
>
One last sub question, is this a good way to make programs in C by
defining a struct and assign function pointers to it to make it look
like a oo.
No. C has a different paradigm, trying to write python using C syntax
as bad an idea as trying using German sentence structure English to
write is.
>Or are there other recommended methods to make a program.
I recommend learning C as a language on its own, and trying to forget
how you might do something in a different language. It will only
confuse you and lead to very inefficient code.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Feb 9 '07 #21
On 9 Feb 2007 13:30:25 -0800, in comp.lang.c , "gert"
<ge**********@g mail.comwrote:
>But you have to admit it looks nice this way not ?
Personally, I think it looks messy, overcomplicated and prone to
errors. C is not C++ or python or Java. I strongly recommend you write
C like C.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Feb 10 '07 #22
On Fri, 09 Feb 2007 14:43:45 +1300, Ian Collins wrote:
>Ian Collins wrote:
>int main(void) {
Obj* obj = malloc( sizeof obj );
Oops, malloc( sizeof *obj );
Why malloc? Why a memory leak?

Best regards,
Roland Pibinger
Feb 10 '07 #23
On Feb 10, 12:55 pm, rpbg...@yahoo.c om (Roland Pibinger) wrote:
Why malloc? Why a memory leak?

Best regards,
Roland Pibinger
Can you collaborated on the memory leak part please ?
How would you do it ?
Feb 10 '07 #24
On Sat, 10 Feb 2007 11:55:04 GMT, in comp.lang.c , rp*****@yahoo.c om
(Roland Pibinger) wrote:
>On Fri, 09 Feb 2007 14:43:45 +1300, Ian Collins wrote:
>>Ian Collins wrote:
>>int main(void) {
Obj* obj = malloc( sizeof obj );
Oops, malloc( sizeof *obj );

Why malloc?
In C, what else would you use to allocate memory than one of the
*alloc family?
>Why a memory leak?
What memory leak?
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Feb 10 '07 #25
gert wrote:
rpbg...@yahoo.c om (Roland Pibinger) wrote:
>Why malloc? Why a memory leak?

Can you collaborated on the memory leak part please ?
How would you do it ?
void leak(size_t howmuch) {
malloc(howmuch) ;
}

will do it nicely, provided you #include <stdlib.h>

--
<http://www.cs.auckland .ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfoc us.com/columnists/423>

"A man who is right every time is not likely to do very much."
-- Francis Crick, co-discover of DNA
"There is nothing more amazing than stupidity in action."
-- Thomas Matthews
Feb 10 '07 #26
On Sat, 10 Feb 2007 18:55:17 +0000, Mark McIntyre wrote:
>On Sat, 10 Feb 2007 11:55:04 GMT, in comp.lang.c , rp*****@yahoo.c om
(Roland Pibinger) wrote:
>>Why malloc?

In C, what else would you use to allocate memory than one of the
*alloc family?
What about putting the object on the stack? In C you do not
dynamically allocate memory unnecessarily.

Best wishes,
Roland Pibinger
Feb 10 '07 #27
Roland Pibinger wrote:
On Sat, 10 Feb 2007 18:55:17 +0000, Mark McIntyre wrote:
>rp*****@yahoo.c om (Roland Pibinger) wrote:
>>Why malloc?

In C, what else would you use to allocate memory than one of the
*alloc family?

What about putting the object on the stack? In C you do not
dynamically allocate memory unnecessarily.
In standard C there is no such thing as a stack, and no mechanism
for placing run-time sized objects in automatic storage space.

--
<http://www.cs.auckland .ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfoc us.com/columnists/423>

"A man who is right every time is not likely to do very much."
-- Francis Crick, co-discover of DNA
"There is nothing more amazing than stupidity in action."
-- Thomas Matthews
Feb 10 '07 #28
On Sat, 10 Feb 2007 21:55:56 GMT, in comp.lang.c , rp*****@yahoo.c om
(Roland Pibinger) wrote:
>On Sat, 10 Feb 2007 18:55:17 +0000, Mark McIntyre wrote:
>>On Sat, 10 Feb 2007 11:55:04 GMT, in comp.lang.c , rp*****@yahoo.c om
(Roland Pibinger) wrote:
>>>Why malloc?

In C, what else would you use to allocate memory than one of the
*alloc family?

What about putting the object on the stack?
I was referring to memory allocation, as opposed to automatics. The
latter aren't dynamic.
In C you do not dynamically allocate memory unnecessarily.
Why not?
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Feb 10 '07 #29
CBFalconer wrote, On 10/02/07 22:49:
Roland Pibinger wrote:
>On Sat, 10 Feb 2007 18:55:17 +0000, Mark McIntyre wrote:
>>rp*****@yahoo.c om (Roland Pibinger) wrote:

Why malloc?
In C, what else would you use to allocate memory than one of the
*alloc family?
What about putting the object on the stack? In C you do not
dynamically allocate memory unnecessarily.

In standard C there is no such thing as a stack, and no mechanism
for placing run-time sized objects in automatic storage space.
Unless you can find a suitable C99 implementation and use VLAs.
--
Flash Gordon
Feb 11 '07 #30

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

Similar topics

17
6531
by: George Sakkis | last post by:
Is there a general way of injecting code into a function, typically before and/or after the existing code ? I know that for most purposes, an OO solution, such as the template pattern, is a cleaner way to get the same effect, but it's not always applicable (e.g. if you have no control over the design and you are given a function to start with). In particular, I want to get access to the function's locals() just before it exits, i.e....
4
2058
by: veereshai | last post by:
i want to copy the functions from my source file into a new file...and convert each function into a new object file by compiling it. now, i want to invoke the function using the object file i have created and not by invoking the original function(i.e delete the part which has the function and then try to invoke the same function by including the object file into my source code). Is this possible?
5
8634
by: Sakharam Phapale | last post by:
Hi All, I am using an API function, which takes file path as an input. When file path contains special characters (@,#,$,%,&,^, etc), API function gives an error as "Unable to open input file". Same file path containing special characters works fine in one machine, but doesn't work in other. I am using following API function to get short file path. Declare Auto Function GetShortPathName Lib "kernel32" (ByVal lpszLongPath As
5
1985
by: Ian Bicking | last post by:
I got a puzzler for y'all. I want to allow the editing of functions in-place. I won't go into the reason (it's for HTConsole -- http://blog.ianbicking.org/introducing-htconsole.html), except that I really want to edit it all in-process and in-memory. So I want the identity of the function to remain the same, even as I edit the body and hopefully the signature too. Well, the reason is that I want to edit any function object, without...
54
24548
by: John | last post by:
Is the following program print the address of the function? void hello() { printf("hello\n"); } void main() { printf("hello function=%d\n", hello); }
27
3135
by: Terry | last post by:
I am getting the following warning for the below function. I understand what it means but how do I handle a null reference? Then how do I pass the resulting value? Regards Warning 1 Function 'Dec2hms' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.
3
3665
by: John Turner | last post by:
typedef void (*vfp)(); typedef vfp (*fp)(); static fp hello() { printf("Hello.\n"); return (fp)&hello; } main(){
3
9291
pbmods
by: pbmods | last post by:
AN INTRODUCTION TO FUNCTION OBJECTS LEVEL: INTERMEDIATE PREREQS: OBJECTS You've seen it before. You're setting up an XMLHttpRequest call, and you need to execute a function when it returns, so you do something like this: http.onreadystatechange = myAwesomeFunction;
5
1499
by: robbiesmith79 | last post by:
Hey fellow nerds, Take this code for example: class hello { function world() { echo "Hello"; } }
1
2396
by: Hunter | last post by:
I am writing a script that needs to send some emails. And I've used smtplib in the past and it is pretty easy. But I thought, gee it would be easier if I could just call it as a function, passing the from, to, subject, and message text. So I wrote it up as a function and it sort of works, but I get a weird error. When it runs it inserts a "\t" tab character before each item during the send portion (which I can see when I turn on...
0
9598
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
10373
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
10111
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
9192
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
6877
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
5683
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4330
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
2
3852
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3010
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.