|
I guess it's only for type of the same size as int....
and a good source of endless bug and fun!
|
|
|
|
|
Nah, on that link, it was shared that compiler runs a multiplication with sizeof(a) itself.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Afzaal Ahmad Zeeshan wrote: I am going to have an exam of C++ tomorrow Good luck on the exam!
Afzaal Ahmad Zeeshan wrote: go back to Haskell once again Yikes!
|
|
|
|
|
Quote: Afzaal Ahmad Zeeshan wrote:
go back to Haskell once again Yikes!
Trust me, Haskell is much easy and simple language. Although I started learning Haskell 2 days ago, I think I am enjoying the much simpler and better syntax.
After all, you also like PHP[^]. Don't you Sander?
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
|
Much respect for you, to bear so much pain, Sander!
I have just started Haskell, and I am very much loving it. I would give these articles of your a look, you have written a great article for Haskell. You got some more I can pay some attention to?
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Afzaal Ahmad Zeeshan wrote: I have just started Haskell, and I am very much loving it. Haskell has good parts. It certainly changed the way I do my C# programming
I just don't see myself writing entire applications in Haskell just yet...
|
|
|
|
|
Quote: I just don't see myself writing entire applications in Haskell just yet... Same thing here, I may never write entire application in Haskell, but I would love to use a few code blocks and make it interact with the WPF applications.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Why not use F#?
That's a whole lot easier to integrate with your C# projects.
You can even do WPF entirely in F# without any hassle/Haskell!
|
|
|
|
|
I know F#, a little bit.
But right now I am getting rid of being "All Microsoft Geek Boy!". I am learning Linux, trying out new flavors of Linux... Currently my choice is
- Ubuntu Studio
- Ubuntu
- openSUSE
So, when I was learning other operating systems, I thought why not learn other frameworks and programming paradigms. I am not learning Haskell for WPF as I am not at all developing WPF these days. I am instead learning functional programming itself. From my research I came to know that LISP, Scala etc. were all easier than Haskell, which provoked me to take Haskell as a challenge. It was a great experience learning Haskell.
No Microsoft based programming for a while... Learning Linux, learning non-Microsoft languages. I mean, there are many frameworks and systems that a programmer must know. After all, there are many already doing the job of "Jimmy Kode[^]" in this world.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Afzaal Ahmad Zeeshan wrote: there are many frameworks and systems that a programmer must know The average programmer only needs to know a few (and knows less)
It's good to know a bit about everything because every new language or framework gives you a new perspective on the ones you already knew.
For example, knowing Haskell made me really appreciate C# again!
|
|
|
|
|
Actually its been awhile since I have programmed in C# or .NET framework. I have been on a tour for C/C++, cross-platform Java, Haskell and Shell programming. IDEs like, Qt, Eclipse (on Linux) and Text editors to write code (without any syntax highlighting) to be compiled using command line compilers and so on.
No doubt, Microsoft has provided us with great tools and languages for programming. Going into native-ness is sometimes pain.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
You masochist, you!
|
|
|
|
|
Quote: You masochist, you! Laugh | I'll take that as a compliment.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Good luck on the exam !
I find that code example frightening Afzaal Ahmad Zeeshan wrote: I can say I know nothing of C or C++ Well, you said the nothing you don't know well enough on this post to get my up-vote: that's something.
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
|
|
|
|
|
Thank you, Bill! But may I ask, it was "frightening" in the sense of?
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Afzaal Ahmad Zeeshan wrote: "frightening" in the sense of? I'd say it's about the same way as I feel looking in a mirror: that sense that what is on the surface is a very bad cover-up of something strange, and probably up to no good
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
|
|
|
|
|
Well, learning C at this era is also upto no good. But, it is worth a shot. Using your example, I would be much more interested in the "man inside" rather than the bad cover-up.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Interesting - actually neat - but it would fail, I think if stretched a bit:
int x=5;
a[x] != x[a];
But your discovery is truly wondrous!
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "As far as we know, our computer has never had an undetected error." - Weisert | "If you are searching for perfection in others, then you seek disappointment. If you are seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
Seems to work fine.
#include <iostream>
int foo(int x, int *a)
{
return x[a];
}
int main()
{
int arr[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int x = 5;
std::cout << arr[x] << " "
<< x[arr] << " "
<< foo(x, arr) << std::endl;
}
Compiles and runs as expected without warning.
|
|
|
|
|
That's unfortunate - I was hoping that the compiler wouldn't accept it because it makes x appear to be an array.
It's not that I don't understand - but one could hope that the compiler would differentiate between the two.
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "As far as we know, our computer has never had an undetected error." - Weisert | "If you are searching for perfection in others, then you seek disappointment. If you are seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
The compiler doesn't do a + 5 , it is worse than that - it does a + 5 * sizeof(5) , so 5[a] becomes 5 + a * sizeof(a) , which is OK, since a is a pointer, and pointers are integers that can be added and multiplied.
Learning something new about Haskell is like buying a new clothes. Learning something new about C/C++ is like discovering the nuclear reaction - it can change you and not always for good. Please, please, don't get twisted, don't go into C/C++ land!
|
|
|
|
|
Thanks,
This was the question I used on applicants who claimed (on a scale of 1..10) a level 9 or 10 knowledge of the C language.
Also, I believe a[5] == *(a+5)
Because a[5] gives you the VALUE, not the pointer to the value
The rule as I learned it, is every [] => * level of de-referencing.
|
|
|
|
|
Here's my favorite obscure C/C++ array trick, to print hex digits.
std::uint8_t byte
char code[3] = 0;
...
code[0] = "0123456789ABCDEF"[byte >> 8];
code[1] = "0123456789ABCDEF"[byte & 0xf];
std::cout << code;
|
|
|
|
|
For the record, this behavior is part of C since K&R. It exists in C++ for backward compatibility. I am not an objective-C guy, but suspect it has same behavior.
|
|
|
|