|
In essence, it means nothing.
Unix people have a wierd sense of humor. There is another famous Unix program called Yacc (which I think stands for "Yet Another Compiler Compiler"), and another named Bison (who knows what that means? Anyway, these are both ruminants (ie cattle), so whatever joker came up with the Gnu project decided to name it after yet another herdbeast. (Why they didn't name it BULL is beyond me.)
Later, some clown decided to get funny and tag a meaningless recursive definition to the name: Gnu's Not Unix. Yawn. I hate to think what these nuts name their kids.
|
|
|
|
|
- Thanks, Jim pal!
- Yep, I think you are right and smart. You must be a fan of UNIX.
- Well, another question arises in my head. I do not know why they do not use the UNIX kernel and write a new version of their own. Why not just implement the binaries of UNIX and use the UNIX kernel? It is a nice kernel, isn't it?
- Can you help?
- Have a nice weekend,
Maer
|
|
|
|
|
- What is the difference between a normal function and a static function?
- For example, static int StaticFunc(int n);
- Can you show me an example?
- Regards,
Maer
|
|
|
|
|
When static is applied to a global function it means the function is visible only in that .CPP file.
--Mike--
http://home.inreach.com/mdunn/
#include "witty_sig.h"
your with and
|
|
|
|
|
- Thanks pal!
- Your reply helps a lot. But I still have a question. What means "global function"?
- Can you show me an example?
- Regards,
Maer
|
|
|
|
|
I'm not sure why you'd make a global function static ( I only glanced at Michael's answer, but whatever he says is most certainly correct. ).
A static function loses one of the characteristics of a normal function, that it must be called from a this pointer. In other words, if I have a class called CGraus, and I add a function called EmptyWallet, the I would need to call it from within my class, or through an instance of my class. A static function is like a static variable, it only exists once. A less frivolous xe examples exists in GDI+. The Bitmap class has a static function called FromFile. This means instead of
Bitmap bm;
bm.FromFile("Claudia Schiffer.jpg");
I do it like this:
Bitmap * bm = Bitmap::FromFile("Michelle Pfeiffer.jpg");
You'll notice when I call the function there isn't necessarily an instance of Bitmap in memory, certainly the constructor for my pointer has not been called, and is in fact called by my method. For this reason, I suspect the most useful way to use static functions is for methods to initialise pointers of the class in question.
I hope I've not muddied the waters too much.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
|
|
|
|
|
To answer your doubt about globally static functions. Basically this goes back to good old C, where there are only two types of functions, global and static. The syntactic difference is that static functions have the word "static" in their definition and global ones do not. Static functions are visible only inside the file in which they're compiled. Global functions are visible among all the files in the project. So if you have files A.c and B.c, they can each have a static function with the same name and the linker will treat them as two different functions. But if you remove the static modifier from them, the linker will see the same (global) function defined multiple times and give you an error.
So, basically, in C you'd want to make a function "static" when it's only going to be used inside the file it's defined and you want to avoid possible name collisions.
Regards,
Alvaro
|
|
|
|
|
Cool - thanks for the reply, that expands on what Michael said and I understand how it works now.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
|
|
|
|
|
- Thanks, Alvaro pal!
- Your reply helps a lot. I still have a question. I think the functionality of "static" changes in C++, it means a function that can be called without a pointer.
- Since I am a newbie, I do not know whether I am correct.
- Yep, still a trouble. Can the function of "static" in the oldie and goldie C still be used in C++? Are they the same?
- Can you help?
- Have a nice day,
Maer
|
|
|
|
|
- You're welcome.
- In C++ "static" can also be used for class/struct member functions. This allows you to call it without having an instance of the class/struct. So if you have this:
class A
{
public: static void foo();
};
You can then call it directly, like this:
A::foo();
without needing to first create an instance of A.
- Static C functions work the same way in C++. They're only local to the file in which they're compiled. So if you have a static C function, only that C file can see it.
- Hope to have helped, but you really need to pick up a couple of C/C++ books and read them thoroughly.
- Regards,
Alvaro
|
|
|
|
|
- Thanks pal!
- You have clarified all my doubts. And thanks for your suggestions.
- Regards,
Maer
|
|
|
|
|
- Yep, Christian pal, I use the static function in a class and not used as a global function.
- I still have a question. In your reply, you mentioned,
"For this reason, I suspect the most useful way to use static functions is for methods to initialise pointers of the class in question."
- Since I am a newbie, I do not understand your meaning.
- Can you give me an example to show the most useful way to use static functions as you mentioned?
- Have a nice day,
Maer
|
|
|
|
|
"For this reason, I suspect the most useful way to use static functions is for methods to initialise pointers of the class in question."
- Since I am a newbie, I do not understand your meaning.
- Can you give me an example to show the most useful way to use static functions as you mentioned?
Probably no example better than the one I gave. In GDI+ the Bitmap class has a method called FromFile and it's static, which means I can start with a Bitmap *, which has not had new called on it yet, and then call the static method, which is a bit like a global function which returns a Bitmap * when given a filename, but being a static function it exists in the namespace of the class. So given that you'll only have one instance of the function AND the function does not require you to have created an instance of the class, a sensible use for them would be to call a function that creates an instance of the class and returns it. I'm sure there are other uses, I use a static function to do a reference count for example.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
|
|
|
|
|
- Thanks, Christian pal!
- Your reply clarifies my doubts. And I still have a stupid question.
- For example, I use a static function named F1 in class A. Can I use the function F1 in another class B without creating an object (or pointer) of class A in class B. ( Suppose class B has no derivation relationship with class A)
- Can you help?
- Regards,
Maer
|
|
|
|
|
In that case it becomes a question of the relationship between A and B. If the function is public or B is a friend of A then that would not be a problem.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
|
|
|
|
|
- Thanks, Christian pal!
- You have clarified my doubts.
- Regards,
Maer
|
|
|
|
|
- Sorry for interrupting again pal!
- I can not find the "FromFile" function. (MSDN-->CBitMap-->class menbers-->)
- Can you help?
- Regards,
Maer
|
|
|
|
|
It's a GDI+ function in the Bitmap class, not a GDI function in the CBItmap class. If you don't have the SDK installed, you won't have access to it, but it's covered in the MSDN.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
|
|
|
|
|
- What is the difference between the following two sentences?
- const static enum { s = 20 };
- const static s = 20;
- Can you show me an example?
- Regards,
Maer
|
|
|
|
|
The first one creates an unnamed enum type, and defines the constant s to have the value 20. I don't know if the const has any effect there since enum values are by definition constants.
The second is a syntax error. It's almost a variable declaration - it's just missing the type. If it were static const int s=20; then it declares a int variable called s , with value 20 that can't be changed (const ) and is visible only in that .CPP file (static ).
--Mike--
http://home.inreach.com/mdunn/
#include "witty_sig.h"
your with and
|
|
|
|
|
Mike,
The second case is technically not a syntax error since the compiler assumes the default "int" type for the variable. Still, it's bad form and should not be used.
Regards,
Alvaro
|
|
|
|
|
- Thanks, Mike pal!
- I still have a question. What means "by definition constants" in your reply?
- Can you show me an example?
- Regards,
Maer
|
|
|
|
|
- What does the following sentence mean?
- Variable is a constant the compiler knows the value at compile time.
- Can you show me an example?
- Regards,
Maer
|
|
|
|
|
couldn't it be the other way round:
constant is a variable the compiler knows the value at compile time.. makes much more sense for me...
bernhard
""Politicians and diapers have one thing in common. They should both be changed regularly and for the same reason."
|
|
|
|
|
- Take a look at the following program:
#include<iostream>
using namespace std;
class a{
private:
static const int s ;
int i[s];
};
const int a:: s=20;
void main()
{ cout<
|
|
|
|