LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 06-20-2013, 03:00 PM   #1
shifter
Member
 
Registered: May 2006
Distribution: Slackware, DragonFly
Posts: 233

Rep: Reputation: 30
Encapsulation and information hiding with pure C language


In what way is it possible to use encapsulation and information hiding principles with C language? (without considering Object Oriented paradigm and C++)
 
Old 06-20-2013, 03:14 PM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,860
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
A well-known method for opaque data-types is the following:
Code:
/* somestuff.h */

typedef struct Stuff Stuff;

extern Stuff *StuffConstruct (int param);
extern void StuffDestruct (Stuff *); 

... other methods ...
Code:
/* somestuff.c */

#include "somestuff.h"

struct Stuff {
...
};

Stuff *StuffConstruct (int param)
{
    Stuff *ptr= malloc (sizeof (*ptr));
    ...
    return ptr;
}

void StuffDestruct (Stuff *ptr)
{
    ...
    free (ptr); 
}

... other methods ...

Last edited by NevemTeve; 06-20-2013 at 03:15 PM.
 
Old 06-20-2013, 04:17 PM   #3
shifter
Member
 
Registered: May 2006
Distribution: Slackware, DragonFly
Posts: 233

Original Poster
Rep: Reputation: 30
Why did you declare functions as "extern" in header file?
 
Old 06-20-2013, 09:48 PM   #4
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
It isn't necessary in this case, but it's often used to indicate that the function is going to be defined in another file (as opposed to later in the same file.) On the other hand, you would need to use extern for a global variable made available by the header to make it a declaration rather than a definition.

Kevin Barry
 
1 members found this post helpful.
Old 06-21-2013, 03:53 AM   #5
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,860
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Everything else is clear?
 
Old 06-21-2013, 04:29 AM   #6
shifter
Member
 
Registered: May 2006
Distribution: Slackware, DragonFly
Posts: 233

Original Poster
Rep: Reputation: 30
Ok, now everything is clear, thank you very much!
 
  


Reply



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
[SOLVED] why we can not say that c++is pure object oriented language ziyamarshal Programming 4 08-16-2012 01:56 AM
Understanding Linux SLL cooked capture encapsulation packet information evilfish Programming 1 10-23-2008 06:04 AM
How to get language information on Linux jbsp72 Linux - General 2 07-14-2008 12:26 PM
LXer: Practical Steganography Part-1: Hiding information in Binary Executable File LXer Syndicated Linux News 0 02-14-2008 11:41 AM
Hiding machine information and root information geletine Linux - Security 6 07-14-2006 07:57 AM

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

All times are GMT -5. The time now is 06:53 AM.

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