any other language can do these?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Tyler
Member
Member
Posts: 514
Joined: Tue Nov 07, 2006 7:37 am
Location: York, England

Post by Tyler »

JamesM wrote:I don't understand how it's inconsistent - In English we say "Let a equal b" as assignment, but we also say "If a is equal to b" as comparison.

Please provide a counterexample.
He is saying... "==" is Comparison, "=" is assignment, therefore using "=" for comparison in "<=" is inconsistent.

He is correct, but that's C for you, the Language with a million meanings for the Static keyword. :P
Craze Frog
Member
Member
Posts: 368
Joined: Sun Sep 23, 2007 4:52 am

Post by Craze Frog »

Tyler wrote:
JamesM wrote:I don't understand how it's inconsistent - In English we say "Let a equal b" as assignment, but we also say "If a is equal to b" as comparison.

Please provide a counterexample.
He is saying... "==" is Comparison, "=" is assignment, therefore using "=" for comparison in "<=" is inconsistent.

He is correct, but that's C for you, the Language with a million meanings for the Static keyword. :P
Exactly.
User avatar
Zacariaz
Member
Member
Posts: 1069
Joined: Tue May 22, 2007 2:36 pm
Contact:

Post by Zacariaz »

i will have to agree, >== would be more logical than >= but its not like it one of the greatest problems humanity has ever faced...


Is C/C++ <BLEEP!> programming languages? I dont qualify to answer that, but i can say this: I still dont understand the static keyword.
This was supposed to be a cool signature...
Craze Frog
Member
Member
Posts: 368
Joined: Sun Sep 23, 2007 4:52 am

Post by Craze Frog »

Zacariaz wrote:i will have to agree, >== would be more logical than >= but its not like it one of the greatest problems humanity has ever faced...
The problem doesn't manifest itself until one changes code to test for less than or equal (<=) into only equal (=).

Is C/C++ <BLEEP!> programming languages? I dont qualify to answer that, but i can say this: I still dont understand the static keyword.
It means different things depending on where it's used.
Static basically means "without change (of status)".

If you declare a static data member it means it's shared between all instances of a class. Thus it's MORE prone to getting changed than non-static variables. In this context the C++ version of static means the OPPOSITE of the english version. Better keyword: shared.

If you declare a static member function it means it's accessible even if there is no instances of the class. These functions MAY (they don't have to) use static call binding, so the name is sort of correct, but it only makes sense if you know more than necessary.
Non-member functions that are NOT static use static binding as well, so there is no logic involved.

If you use static on local variables, it means they are shared between all subsequent and parallel invocations of the function. The name still makes most sense with respect to linkage.

If you static on global variables or functions, it means they have file scope. That doesn't make sense at all.
User avatar
Zacariaz
Member
Member
Posts: 1069
Joined: Tue May 22, 2007 2:36 pm
Contact:

Post by Zacariaz »

Craze Frog wrote:
Zacariaz wrote:i will have to agree, >== would be more logical than >= but its not like it one of the greatest problems humanity has ever faced...
The problem doesn't manifest itself until one changes code to test for less than or equal (<=) into only equal (=).

you could argue that "<=" == "< | ==" ;)

The static keyword have allready been explained to me in severel times, however it think this took me a little bit further on the path to enlightenment, thank you for that.
Last edited by Zacariaz on Thu Oct 04, 2007 12:26 pm, edited 1 time in total.
This was supposed to be a cool signature...
Craze Frog
Member
Member
Posts: 368
Joined: Sun Sep 23, 2007 4:52 am

Post by Craze Frog »

Zacariaz wrote:It have allready been explained to me in severel times, however it think this took me a little bit further on the path to enlightenment, thank you for that.
Yep, the difficult part isn't actually understanding it, but remembering where it means what.
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Post by neon »

static simply means the object has properties of a global, but has limited scope depending on where it is defined at.

Not that hard.

static data members declare the object as a global, but limited to the scope of the class. Hence, all objects of the class can access it.

Code: Select all

class a {

public:
   static int m_data;  // has properties of a global.
};

// As it is limited to the scope of the class definition, only objects of this
// type can access the variable.

// Because it is a global variable, we need to give it a definite presence
// by defining it globally.

int a::m_data=0;             // the global object is actually defined here.
static member functions are the same way. Declaring a member function as static is similar to declaring a non member function as static. Under both instances, they have the properties of a global function.

In the case of a member function, the function is globally defined, but has limited scope to the class. It works the same way data members do:

Code: Select all

class a{

public:
   static void foo ();  // this function had the properties of a global function
                             // but is limited to the scope of the class definition.
};

// Because the function is global, we need to define it globally:

void a::foo () {

}
Under both data members and member functions, all objects of the class can access this data and routine as if they were globally defined. The reason is because they are--They just have limited scope.

static Local variables are the same way. As they have properties of global variables, they are not destroyed on function exit.
If you static on global variables or functions, it means they have file scope. That doesn't make sense at all.
Yes it does. static data are meant as another way of specifying data and routines with properties of globals, not external symbols.
Yep, the difficult part isn't actually understanding it, but remembering where it means what.
Under every situation listed here, static has always meant the same thing: It declares data or routines with the properties of a global, inside of limited scope. It does not mean anything different.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

Oh dear, here we go again. Truth train to the rescue!
The problem doesn't manifest itself until one changes code to test for less than or equal (<=) into only equal (=).
Please name me an imperative programming language that does not use the '=' character in both assignment and comparison (with the obvious exception of bash (-eq) ).
Quote:
Is C/C++ <BLEEP!> programming languages? I dont qualify to answer that, but i can say this: I still dont understand the static keyword.
Of course they are programming languages.
If you declare a static data member it means it's shared between all instances of a class. Thus it's MORE prone to getting changed than non-static variables. In this context the C++ version of static means the OPPOSITE of the english version. Better keyword: shared.
It's a global variable with namespace scoping.
If you declare a static member function it means it's accessible even if there is no instances of the class. These functions MAY (they don't have to) use static call binding, so the name is sort of correct, but it only makes sense if you know more than necessary.
Non-member functions that are NOT static use static binding as well, so there is no logic involved.
I can explain static member functions in one sentence: "Does not contain a 'this' pointer".

The call binding used is no different whether declared static or non static. And of COURSE non-member functions are statically bound - they have no vtable!
If you use static on local variables, it means they are shared between all subsequent and parallel invocations of the function. The name still makes most sense with respect to linkage.
Ugh. What about the linkage? It's the same as any other global variable apart from it can only be accessed from within the defining function.
If you static on global variables or functions, it means they have file scope. That doesn't make sense at all.
I think you'll find that's a throwback to C, where that was the only way the keyword 'static' could be used (notice above everything we talk about is C++ specific).
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Post by Colonel Kernel »

neon wrote:

Code: Select all

class a {

public:
   static int m_data;  // has properties of a global.
};

// As it is limited to the scope of the class definition, only objects of this
// type can access the variable.
No, you'd have to declare it private for that to be true. static does not imply private.
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Post by neon »

Colonel Kernel wrote: No, you'd have to declare it private for that to be true. static does not imply private.
You are absolutely correct :) I was in a hurry writing that -_-
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
Zacariaz
Member
Member
Posts: 1069
Joined: Tue May 22, 2007 2:36 pm
Contact:

Post by Zacariaz »

JamesM wrote:
The problem doesn't manifest itself until one changes code to test for less than or equal (<=) into only equal (=).
Please name me an imperative programming language that does not use the '=' character in both assignment and comparison (with the obvious exception of bash (-eq) ).
It is not of any importants how things are done currently, what is the subject of this part of the discussion is whether it can be done better, and i believe it can.
JamesM wrote:
Quote:
Is C/C++ <BLEEP!> programming languages? I dont qualify to answer that, but i can say this: I still dont understand the static keyword.
Of course they are programming languages.
"<BLEEP!>" obviously not obviously meaning "very bad word" || "string of very bad words"
This was supposed to be a cool signature...
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

Zacariaz wrote:
JamesM wrote:
The problem doesn't manifest itself until one changes code to test for less than or equal (<=) into only equal (=).
Please name me an imperative programming language that does not use the '=' character in both assignment and comparison (with the obvious exception of bash (-eq) ).
It is not of any importants how things are done currently, what is the subject of this part of the discussion is whether it can be done better, and i believe it can.
No, the initial point was a rant (by Craze Frog, not you) about how terrible C is. I would assume this was in comparison with other current languages and not just "C is obsolete, but I'm not going to give any idea for a replacement..."
JamesM wrote:
Quote:
Is C/C++ <BLEEP!> programming languages? I dont qualify to answer that, but i can say this: I still dont understand the static keyword.
Of course they are programming languages.
"<BLEEP!>" obviously not obviously meaning "very bad word" || "string of very bad words"
Well, as mentioned earlier, C has stood the test of time. It would therefore occur to me that anyone who thinks C is <BLEEP!> should either 1. suggest a better alternative or 2. learn to use it properly. I consider myself fluent in C, and have no issues performing any task. please note I am not saying here that C is the best language in teh world eva!!111!!1 - just for certain jobs, like OSDev.
User avatar
Zacariaz
Member
Member
Posts: 1069
Joined: Tue May 22, 2007 2:36 pm
Contact:

Post by Zacariaz »

JamesM wrote:
Zacariaz wrote:
JamesM wrote:Please name me an imperative programming language that does not use the '=' character in both assignment and comparison (with the obvious exception of bash (-eq) ).
It is not of any importants how things are done currently, what is the subject of this part of the discussion is whether it can be done better, and i believe it can.
No, the initial point was a rant (by Craze Frog, not you) about how terrible C is. I would assume this was in comparison with other current languages and not just "C is obsolete, but I'm not going to give any idea for a replacement..."
admitet, that was a bit oftrack, however the quote i was replying to made no sence otherwise:
if(C == crappy) find better language.
else if not possible accept it and live with it.

Thats not an argument at all. Nor is it an solution or usefull in any way.

Just because every single programming language you know about uses the = operator in this fasion, doesnt mean it is right.

We have poluted our planet for like 200 years and only now we discover that it was probably not the best thing to do.

Improvements are made all the time, but often it is the small ones which is hardest to handle.
This was supposed to be a cool signature...
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

admitet, that was a bit oftrack, however the quote i was replying to made no sence otherwise:
if(C == crappy) find better language.
else if not possible accept it and live with it.

Thats not an argument at all. Nor is it an solution or usefull in any way.
I disagree. It *is* and argument. And is *is* useful, given the OP's comments - he was not bashing "programming languages", he was complaining about "C as a programming language". A similar point could be made: C is <Bleep!>: It's so overly complex it can't be represented by a finite state automaton! Pushdown-stack automata are far too much overkill - C must be simpler!. Is this point worth listening to? No. Why? Because the poster doesn't provide a counter-example or example of another alternative language which meets his needs.

"The syntax used in programming languages today is obsolete" does not equal "C's syntax is obsolete". It's that difference that annoys me.
User avatar
mcheung63
Member
Member
Posts: 175
Joined: Thu Jun 22, 2006 8:33 am
Location: Hong Kong
Contact:

Post by mcheung63 »

I need customer linking (support linker script), because it is easier to control the layout of the kernel file.

Can pascal produce a ELF object file or executable file? If yes, then it can cooperate with the gnu ld.

thanks
from Peter
Post Reply