Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > c can protect the data in struct

Reply
Thread Tools

c can protect the data in struct

 
 
satheesh
Guest
Posts: n/a
 
      02-27-2008
c language can protect the data in scopes private,protected and
public(may be) in structure and union?
 
Reply With Quote
 
 
 
 
santosh
Guest
Posts: n/a
 
      02-27-2008
satheesh wrote:

> c language can protect the data in scopes private,protected and
> public(may be) in structure and union?


No it can't. It can be hidden from direct access from an outer scope or
from another translation unit, but nothing anywhere in a C program's
address space can be absolutely protected from any other part of
itself.

Maybe you can clarify your question?

 
Reply With Quote
 
 
 
 
satheesh
Guest
Posts: n/a
 
      02-27-2008
On Feb 27, 6:35*pm, santosh <santosh....@gmail.com> wrote:
> satheesh wrote:
> > c language can protect the data in scopes private,protected and
> > public(may be) in structure and union?

>
> No it can't. It can be hidden from direct access from an outer scope or
> from another translation unit, but nothing anywhere in a C program's
> address space can be absolutely protected from any other part of
> itself.
>
> Maybe you can clarify your question?


yes.
c++ having the data abstraction like protect, private.
c structure writes with protect, private also.
example:
struct bio
{
protect int a,b;
public:
void read()
void display()
};
what is the different between the c structure's protected, private and
c++ class's protected, private.

 
Reply With Quote
 
suresh shenoy
Guest
Posts: n/a
 
      02-27-2008
On Feb 27, 8:47*am, satheesh <satheesh....@gmail.com> wrote:
> On Feb 27, 6:35*pm, santosh <santosh....@gmail.com> wrote:
>
> > satheesh wrote:
> > > c language can protect the data in scopes private,protected and
> > > public(may be) in structure and union?

>
> > No it can't. It can be hidden from direct access from an outer scope or
> > from another translation unit, but nothing anywhere in a C program's
> > address space can be absolutely protected from any other part of
> > itself.

>
> > Maybe you can clarify your question?

>
> yes.
> c++ having the data abstraction like protect, private.
> c structure writes with protect, private also.
> example:
> struct bio
> {
> * *protect int a,b;
> * *public:
> * *void read()
> * *void display()};
>
> what is the different between the c structure's protected, private and
> c++ class's protected, private.


I did a search of private/ protected in ISO/IEC 9989 but did not find
anything. Where did u see this?

Suresh M. Shenoy
 
Reply With Quote
 
santosh
Guest
Posts: n/a
 
      02-27-2008
satheesh wrote:

> On Feb 27, 6:35*pm, santosh <santosh....@gmail.com> wrote:
>> satheesh wrote:
>> > c language can protect the data in scopes private,protected and
>> > public(may be) in structure and union?

>>
>> No it can't. It can be hidden from direct access from an outer scope
>> or from another translation unit, but nothing anywhere in a C
>> program's address space can be absolutely protected from any other
>> part of itself.
>>
>> Maybe you can clarify your question?

>
> yes.
> c++ having the data abstraction like protect, private.
> c structure writes with protect, private also.
> example:
> struct bio
> {
> protect int a,b;
> public:
> void read()
> void display()
> };
> what is the different between the c structure's protected, private and
> c++ class's protected, private.


Your code is *not* C. It is probably C++, which treats struct and class
as essentially the same, or perhaps some proprietary dialect of C.

There are no keywords like 'public', 'protected' or 'private' in C. Try
comp.lang.c++

 
Reply With Quote
 
satheesh
Guest
Posts: n/a
 
      02-27-2008
i studied in trichy LINSOFT. He teach this program.
 
Reply With Quote
 
santosh
Guest
Posts: n/a
 
      02-27-2008
satheesh wrote:

> i studied in trichy LINSOFT. He teach this program.


Well, he (or it) taught you wrong then. See the following document for
the best authoritative definition of the C language short of actually
buying the ISO Standard for it.

<http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf>

 
Reply With Quote
 
Randy Howard
Guest
Posts: n/a
 
      02-27-2008
On Wed, 27 Feb 2008 08:00:34 -0600, satheesh wrote
(in article
<8b1d4b15-cdb2-45dc-8004->):

> i studied in trichy LINSOFT. He teach this program.


"He" is wrong. C does not have these features. Compiling code that is
/claimed/ to be C with a C++ compiler doesn't make it true.


--
Randy Howard (2reply remove FOOBAR)
"The power of accurate observation is called cynicism by those
who have not got it." - George Bernard Shaw





 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      02-27-2008
satheesh wrote:
> c language can protect the data in scopes private,protected and
> public(may be) in structure and union?


C has no "private" or "protected" or "public" scope.
Are you thinking of some other language?

--
Eric Sosman
lid
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      02-27-2008
satheesh <> writes:
> On Feb 27, 6:35Â*pm, santosh <santosh....@gmail.com> wrote:
>> satheesh wrote:
>> > c language can protect the data in scopes private,protected and
>> > public(may be) in structure and union?

>>
>> No it can't. It can be hidden from direct access from an outer scope or
>> from another translation unit, but nothing anywhere in a C program's
>> address space can be absolutely protected from any other part of
>> itself.
>>
>> Maybe you can clarify your question?

>
> yes.
> c++ having the data abstraction like protect, private.
> c structure writes with protect, private also.
> example:
> struct bio
> {
> protect int a,b;
> public:
> void read()
> void display()
> };
> what is the different between the c structure's protected, private and
> c++ class's protected, private.


Both C and C++ have "struct" types. A C struct declaration is very
likely to be a valid C++ struct declaration, but not vice versa;
*some* C++ struct declarations are valid C struct declarations, but
not all.

<OT>
In C++, the only difference between a struct and a class is that
struct members are public by default, and class members are private by
default. Either a struct or a class can use all the C++-specific
features that don't exist in C; public, private, protected, member
functions, inheritance, etc. But as a matter of C++ programming
style, the usual convention is to use the "struct" keyword for the
relatively simple types that would also be valid in C, and the "class"
keyword for types that depend on C++-specific features. The reasons
for this rather odd state of affairs are rooted in the history of the
C++ language, which is very much off-topic here. For more C++
information, read a good C++ textbook, or the C++ FAQ at
<http://www.parashift.com/c++-faq-lite/>, or post to comp.lang.c++ or
comp.lang.c++.moderated.
</OT>

(The "OT" tags above mean "off-topic", indicating that discussions of
C++ are generally in appropriate here in comp.lang.c. I'm making an
exception here because the point is to illustrate something about C.)

So your type "struct bio", though it's a valid declaration in C++ (or
would be if fixed a few syntax errors), really should have been
declared as a class, not as a struct. As I said, *some* C++
declarations are also valid C declarations; your "struct bio" is not.
It's not the "struct" keyword that a C++ type valid in C; it's the
features used within it (the stuff between the curly braces). Try
feeding your declaration to a C compiler, and you'll see what I mean
(here gcc is acting as a C compiler, and g++ is a C++ compiler):

% cat bio.c
struct bio {
protected:
int a, b;
public:
void read();
void display();
};
% g++ -c bio.c
% gcc -c bio.c
bio.c:2: error: parse error before "protected"
bio.c:2: warning: no semicolon at end of struct or union
bio.c:7: error: parse error before '}' token

(The warning about the missing semicolon is spurious; compilers are
often confused by syntax errors.)

And keep in mind that, in spite of their superficial similarities, C
and C++ are really two different languages, and should (almost always)
be treated as such.

--
Keith Thompson (The_Other_Keith) <kst->
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can *common* struct-members of 2 different struct-types, that are thesame for the first common members, be accessed via pointer cast to either struct-type? John Reye C Programming 28 05-08-2012 12:24 AM
Typedef A references struct B which references struct A which... DanielEKFA C++ 8 05-16-2005 10:26 AM
struct in struct Gunnar G C++ 14 06-02-2004 06:43 PM
struct my_struct *p = (struct my_struct *)malloc(sizeof(struct my_struct)); Chris Fogelklou C Programming 36 04-20-2004 08:27 AM
implementing a templated struct within a templated struct RA Scheltema C++ 3 01-06-2004 11:25 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57