some people do:
- #define public
- #define private static
but it is not a C keyword.
EDIT:
For those who think it is a bad idea to do that, I would agree... but it does explain why someone might think "public" or "private" were C keywords.
For those who think it won't compile in C... try this:
#include <stdio.h>
#include <stdlib.h>
#define public
#define private static
private void sayHello(void);
public int main(void)
{
sayHello();
return (EXIT_SUCCESS);
}
private void sayHello(void)
{
printf("Hello, world\n");
}
For those who think it won't compile in C++, yes the above program will. (Edit) Well actually it is undefined behaviour due to this part of the C++ standard:
A translation unit that includes a
header shall not contain any macros
that define names declared or defined
in that header. Nor shall such a
translation unit define macros for
names lexically identical to keywords.
So the example above and below are not required to do anything sane in C++, which is a good thing. My answer still is completely valid for C (until is is proved to be wrong! :-)
In the case of C++ a class with private members you can do a similar (abuse) like this:
#include <cstdlib>
#define private public
#include "message.hpp"
int main()
{
Message msg;
msg.available_method();
msg.hidden_method();
return (EXIT_SUCCESS);
}
#ifndef MESSAGE_H
#define MESSAGE_H
#include <iostream>
class Message
{
private:
void hidden_method();
public:
void available_method();
};
inline void Message::hidden_method()
{
std::cout << "this is a private method" << std::endl;
}
inline void Message::available_method()
{
std::cout << "this is a public method" << std::endl;
}
#endif