LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-23-2001, 11:44 AM   #1
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
C Practises


I'm learning C++ from a shaky Java background, and two things i don't quite understand are....

1) The use of pointers. Source code in C seems to use pointers to objects as a matter of course, rather than directly using them...

main (int argc, char *argv[])
{
GtkWidget *window;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_show (window);
gtk_main ();
return 0;
}

Why the insistence on all the *'s and &'s and ->'s ?

2) Header files

I don't understand the practise of defining a class with empty methods and such like in a .h file and then seeming to basically overwrite them in the .c with ...

aClass::aMethod() { ... }

I can understand how a header file can set out things in a presentable and approachable manner... but the whole :: thing... I can't see why that isn't really bad practise.

thanks
Chris
xxxx
 
Old 07-23-2001, 05:59 PM   #2
isajera
Senior Member
 
Registered: Jun 2001
Posts: 1,635

Rep: Reputation: 45
getting a firm understanding of pointers is probably the most difficult thing for anyone learning C or C++. personally, i agree with you about the :: notation. it's damn annoying in my book.

trust me tho, you'll learn to love pointers (pause here for anyone who wants to burst out laughing)... they are probably the biggest reason why C is as successful as it is, and as fast. once you learn how to use them, you'll wonder how you ever did without them.

if you need any specific explanation of pointers, let me know. i'll see what i can do to help.
 
Old 07-23-2001, 09:16 PM   #3
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
Header files allow you to publish your API (for you and the compiler) and hide the implementation (.c and .cpp files) in a pre-complied library.

Pick the function 'stat' as an example. From the header file you can see the method signature, and you can complile against it so the complier know that it exists. Come link time you link in the lib???.a file and wala. stat works without you knowing any details of how it works.
 
Old 07-24-2001, 03:02 PM   #4
isajera
Senior Member
 
Registered: Jun 2001
Posts: 1,635

Rep: Reputation: 45
yeah... headers are useful... it's that damn :: notation that i can't stand
 
Old 07-25-2001, 03:43 AM   #5
mcleodnine
Senior Member
 
Registered: May 2001
Location: Left Coast - Canada
Distribution: s l a c k w a r e
Posts: 2,731

Rep: Reputation: 45
Uhhh. So. Um, no pun intended, but do you have any pointers for pointers? Like some links, mebbe? The subject has led me to abandon C every time I get to it. But reality dictates that there is only so much one can accomplish with #!/bin/bash, and playing with perl was fun until I got to the part about "pointers, just like the ones C programmers use".

Ack!
 
Old 07-25-2001, 04:23 PM   #6
isajera
Senior Member
 
Registered: Jun 2001
Posts: 1,635

Rep: Reputation: 45
the basic concept of pointers isn't hard to understand at all - i think it's the syntax that weeds out most would-be-c-programmers.

trust me tho, a forum is not really the place to learn about pointers. if you have specific questions, then ask away, but don't ask for a generic pointer primer

i did a quick search, and this site seems ok:
http://pw1.netcom.com/~tjensen/ptr/pointers.htm

Last edited by isajera; 07-25-2001 at 04:27 PM.
 
Old 07-31-2001, 05:36 PM   #7
simon
LQ Newbie
 
Registered: Jul 2001
Posts: 23

Rep: Reputation: 15
Yes you can have pointers to pointers. The only reason I have seen this done is for dynamic arrays. You declare it as "<type>** <variable>;" Dynamic arrays can be quite useful in some situations.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux Standards/Good practises BradAus Linux - Newbie 9 04-05-2005 12:59 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration