Are these really the basics of programming in C++ with visual studio 2008?

Pages: 1234
closed account (4z0M4iN6)
Hi clanmjc

you are discussing like the specification would be the bible. Do you think and believe such definitions, like what a bug is?

I didn't study informatics, so I don't exactly know the definitions, I read something like:

A bug is, if an implementation dont' behave like the specification.

And:

Not a bug is, if the implementation behaves like the specification.

Do you think, the last sentence is true?
If true, true for whom?

I would like, you think this over. Maybe you will find the answer.
It took you days, and 15+ posts to understand the shallow copy vs deep copy before you "finally" got it. Before you got it, you shut down every good explanation for what you were witnessing. I don't expect you to read my last post and immediately understand it either. Take your time, do a little research, it will be crystal clear soon enough.
closed account (4z0M4iN6)
Hi clanmjc

I know, what is a shallow and a deep copy.

The problem is: there is nothing to copy. There is only a special kind of allocated memory (physical RAM, which can be accessed by PCI boards) and which shall not be deallocated.

I only needed: the destructor shall not be called!

Maybe you don't like to think about my question - the last one, which I asked you?
Last edited on
I'm not even sure why I'm bothering anymore... but if you want to keep an object, don't destroy it.
It's that simple. If an object representing memory like you're describing cannot logically be copied, delete the copy constructor. If you want to still be able to move the reference to that memory between object instances, provide an appropriate move constructor and move assignment operator.

The rest of your pseudo-philosophical spiel has no place on a programming forum. There are clearly defined rules about this laid out in the C++ standard, whether you like them or not.
Learn those rules before you attempt a serious project, a discussion about the topic or before having the nerve to claim a compiler's implementation has a bug.

Good luck with the rest of programming career or trolling career, whichever may be the case.
closed account (4z0M4iN6)
Maybe you can also understand some of my thinking.

Sometimes we think this. Later we learn something and rethink what we thought before. Times changes and what was good before can become wrong, only because circumstances changed, some what was wrong before can become good later. Every day we learn something new. I can learn and can change my believings. And so also can you and do you.

But some rules are basic rules of my thinking. And if I would change these rules, I wouldn' know how to think anymore.

And such rules are rules like:

if a = b = c
then a = c

This rules I have chosen, not to change. What you choose, you decide.
It's not my intension to convince you to decide, like I decided.
But you should also accept my decison, which I made for me - not for you.

And if I have my thoughts and maybe would think like: why did they have named this "="? They should have named it "‡"!. Why should this bother you? Every body is free to make up his mind or, how do you think?

And what was whole the discussion about?
You named it "=" and I named it "‡".

But maybe, I misunderstood and you also ment "‡"?

And what was then our discussion about?

I repeated: it's a bug for "="!
And you repeated: but not for "‡"!

And I ment: you mean "=".
And you ment: I mean "‡".
Last edited on
@dadabe
I don't know if its a language barrier but your posts come off sounding condescending, and often make little sense (to me at least). It seems like you are argueing that defined behavior is a bug but at this point its pretty hard to keep track.
closed account (4z0M4iN6)
My meaning was, the assignment "=" should behave, like the "=" we are used in mathematics and logics, not the same as == but logical.

And what had happened, I explained in my last post. Some people will have understood, some people not.
Last edited on
dadabe wrote:
Some people will have understood, some people not

I'm fairly sure the not are in the majority.

dadabe wrote:
the assignment "=" should behave, like the "=" we are used in mathematics

And for the most part it does, but you cant expect the compiler to perform a deep copy on any pointer members without an overloaded operator=. I assume you mean the compiler should automatically deep copy, which would save time and aggravation for beginners. I can only assume this is by design (I haven't read the standard) as there are likely instances where you wouldn't want a deep copy (though I cant think of an example off hand).
Shared pointers is just one example.
closed account (4z0M4iN6)
naraku9333 wrote:
I'm fairly sure the not are in the majority.


Yes, naraku9333 you see this very clear.
This discussion remembered me much of some tales, which I had read before many many years ago - and forgot. These were tales about a wise men, who seemed to be a troll. I thought of it as funny stories and couldn't grasp the whole meaning, but now I understood and can now understand many things, which I didn't understand before.
Understanding sometimes takes many years, so don't worry if you don't understand something.

==============================================
And what this wise man said about such a case, was:

If somebody finds out something, which he might think would be important, and should be told the experts, then this would happen:

Could be, a few are interested.
A lot will be not.
And most don't understand it.

==============================================

And I understood something, what the brother of my boss told me.
He had overlooked some of my emails.

I had thought, there were bugs in a software, which we would like to buy. And I wrote emails to this company and told, what I thought, and made assumptions.

He said, I should not make any assumptions, but only ask questions, and maybe he also could have thought, I wouldn't learn this.
But now I also learned this.

Hi you all, I have to thank you for this very interesting discussion. I could learn, so much of it. Sorry, that I had caused much trouble, because I did't know it before.

What I learned

- don't tell something,
- ask questions
- don't expect an answer
- don't discuss an answer
- say Thank You

Now I can make it much better
And it's so simple

Is this a bug?
You say: No
I say: Thank You

========================================

Today the boss of my brother was here in the company, and I told him I've learned it. He said yes, and important: say Thank You

And then he said, he thinks it difficult, that people, who are not young any more, can learn something new.

Then I thought about this and thought, it seems to me, that many people, who are young have difficulties to learn something new. And then I understood, why it's difficult for old people to learn something new. And you know, times change and later it would be neccessary to learn something new. But if young people finish their high school and don't learn something new, they will not know anymore, how to learn something new, when they are old.

But if somebody learns something new all days and all of his live and if he knows, how to learn something new, he would be an expert in learning something new when he is old. Maybe nobody thought about this.

Perhaps it would be a good idea to think about this.
================================================

And the mistake, which I made:

If you think, there is a bug in a specification, never ask the programmer.
===================================================

Maybe you would like to know, how I could find out all this, of this discussion?

I've learned, how to think.
Especially, how to think, that I can learn something new.

Because of this, I also became an expert in finding bugs.

And what I had to do: look for the bug in this conversation.

===================================================

You remember, there is one simple bug.

And it's incredible, what you can learn of only one bug, if you know, how to think.

===================================================

Thank you all
Last edited on
closed account (zb0S216C)
dadabe wrote:
"I'am a newsbie with only half a year programming experience in C++ and 3 weeks in Visual Studio 2008 C++"
dadabe wrote:
"I also became an expert in finding bugs."

Yeah, sure you have - only if it was that easy.

It's simple: If you don't like the fact that there might be a bug in Visual C++ '08 (or it's a strong possibility that it's a result of a compiler optimisation), move to the newer Visual C++ '10 edition.

Wazzak
Last edited on
closed account (4z0M4iN6)
Framework wrote:


dadabe wrote:

"I'am a newsbie with only half a year programming experience in C++ and 3 weeks in Visual Studio 2008 C++"

dadabe wrote:
"I also became an expert in finding bugs."


Yes, newsbie in C++. Sorry I didn't think it would be important, to tell about C, assembly and other programming languages.

Maybe you can remember the home computer age.
This was the time before internet, before PCs became cheap and had graphics and had Windows.

People wanted to learn about programming. So they bought home computers like Commodore 64 and home computer magazines and typed in the programs, which they found there for learning.
Commodore 64 was quite expensive - about 500 $, but then there were simliar Home Computers, which were a Flop of business, like C16, C160 and Plus4, and these were sold very cheep (Plus4: 50 $).

I bought one, bought such a magazine, wanted to type in such a program listing and saw a bug.

I wanted to complain about the bug, looked for the address of the publishing house, found at the backside of the magazine a job advertisement for an editorial journalist in this home computer magazine publishing house, wrote a job application, came there, worked one week for probation and got the employment.

The wirst what they needed, was: people who typed in the listings, made mistakes during typing and complained about bugs in the listings. Another big publishing house had a solution. An editor - many pages of listing - with which the people could type in their code and saw a checksum, which showed them, they had typed correct. Such a program also was needed by this publishing house.

I gave them my solution: 40 bytes of machine code, which a BASIC program poked to the RAM memory, using the function "poke(address,value)", for calculating a checksum and print on the screen, and a bended pointer, that this would happen after people had typed in a line of code and pressed return. Maybe nobody in the world had thought of such a solution. And this solution worked very fine.

The publishing house got many listings, which learning people had written, who liked, these programs should be published and sold, so they could get some money, which a student with not much money could need.

There were many programs which would have been fine, if they wouldn't have contained a few or a lot bugs.

I thought, if I would fix such bugs, the publishing house would be delighted and also the students and other youngs and olds would be this. And so I did, and got many letters of thanks, because the listings were published and I had shown them, how to write a fine working and fine code. I don't know for how much such programs, I never had seen before - I had fixed the bugs during fife years. I estimate a number between 500 or 1000, and this wasn't the real work of an editorial journalist, just a hobby, which I did by the way in the office.

Another hobby was to impart knowledge about computers, hardware, processor and assembler, and how to write a fine code. For example I wrote an assembler course for 8086 processor, of maybe only 20 pages, but got so much thanks, of a man, who had tried to learn this of books, which were published, but he had tried this in vain. And my course he had understood immediately and now could program assembler.

Another hobby were some small hardware inventions. People could use Commodore printers. If they wanted to use other printers, they had to buy a hardware interface, maybe about 50 $. Some peoble liked to get such things cheeper. So I made for them a small program (similiar the checksum program), so that they could connect a cable, with a centronics connector and another connector to the user interface connector of the plus4, C64, C128. But C16 und C160, didn't have such a user interface connector, only a serial connector for Commodore hardware with only 3 lines for data transfer. A shift register and a nand gate, soldered into a centronics connector (10 lines needed) and a small software program was a cheap solution for them.

I liked these times, although they were stressy, with such hobbies besides the editorial work. But about 1990 the home computer age ended, because PCs became cheap and with graphics and Windows - the good old age never will come back - what a pity. And how could I do such things, when I never had studied informatics and rarely had read any book?

Maybe because before I had 2 years of experience in programming. A gynecologist had bought a PC and needed a program for managing his practice. And before I had some months of programming dBase, a data base with basic like programming language.

The gynecologist had looked the market for such a program, but there was none, which he thought would be fitting. Then I made this program for him. But dBase was too slow for him and other products even so. The best would have been, if he would have decided to buy C for programming an own data base system. Because he didn't buy this, but because he had a book with register and command description for the 8086 processor, I took this book and implemented the practice managing program including the data base system in assembler and this program was so much faster as all the other programs. But this I would never do again, because what should he do, after I found a better paid job and maybe the program needed attendance and update.

There would be much stories to tell. After I had read a book about C, I didn't try a program like "Hello World", but I implemented a text editor, which was very useful for me and was much faster than others with much less code, because it had a nice trick.

I can't tell all my stories, but maybe you now may imagine more about me.

If you know someone with as much bug fixing experience for programs he didn't ever had seen before and without any specification and only a meager or none user documentation, so that I had to test the programs, for looking, what they would do and writing the documentation also by myself - if you know anybody with such an experiece, please tell me, I would be much delighted, if I could meet him.

And if you would think, my experience would not be so much, then you should consider, that I also did something the last 20 years and not only before.

A will try, to remember the books:

- description of the home computer including the programming language BASIC
- book about microprocessor hardware
- register and command description of the 6502 processor from an home computer magizine article
- ROM listing (listing of the home computer firmware in assembler with not much comments)
- dBase book
- book with 8086 register and command description
- book about FORTH
- book about C (Kernighan and Ritchie)
- book about C++
- book about digital electronics
- book about analogue electronics
- book about JAVA
- book about HTML

Other documentations from Web - PHP, Perl, MySQL, JavaScript, Apache ..

Could be a few more, but can't remember jet
Last edited on
Cool story.

Sorry all for this long post, I work with some people like this, I have to get this off my chest.

dadabe said "half a year programming experience in C++ and 3 weeks in Visual Studio 2008 C++ and I don't know much about the finesses of programming in C++"
Correct, you don't know about the finesses of C++

dadabe said
"No it's not me who is the newbie. Maybe all others, who are programming in Visual Studio 2008 C++ are newbies. Most of them, because they don't know about the basics of Visual Studio 2008 C++ and some, because they don't know about programming generally in C++."

You've already made it clear, you only have half a year of C++ programming, clearly, you are now making bad assumptions.

dadabe said
"Yesterday I made some tests, and now I know exactly about the basics of programming in Visual Studio 2008 C++."

Unfortunately, every one of your conclusions about the basics is incorrect, but you claim you know exactly about them.

dadabe said
"The first Basic
Before you assign a new content to an existing object, you first have to destruct the old content."

Completely incorrect. Shows your complete lack of understanding of the C++ language, forget about what compiler. This is based off you not knowing how the copy assignment/ copy construction, move assignment/move construction works.

dadabe said
"The second Basic
Consider the difference between an used and an unused object.
If you assign a new instanciated temporary object to an existing object, don't delete the temporary object, but only free the memory."

Completely inccorect as well. For the same reason as above.

dadabe said
"The third Basic
Use classes, which can disable destruction."

... Again based off your 2 basic rules, which are entirely incorrect.

coder777 said
"The problem you're faced with is likely the 'shallow' vs 'deep' copy."
dadabe said
"I know, what you mean, but it was not a problem like shallow and deep, the pointers were all ok."

You don't know what is meant by that, it was clearly your problem. You didn't even know, at this point, that move construction/assignment even existed.

Peter87 said
"It looks like you have not overloaded the copy constructor and copy assignment operator correctly or not at all."

And you didn't, not in your posted code, so if there was ANY allocated memory anywhere in your Cat classes... your hosed.

dadabe said
"why should I have to overload a standard copy operator for such a basic thing, like:"
MyCat = CatFrisky;

Clearly, you don't understand C++ by asking this. You are confusing C++ with C making these assumptions.

dadabe said
"Maybe you are right and I don't know so much about the correct behavior of C++ compilers. It seems I only expected too much. But I will try gcc and then I can see, what this compiler does."

Finally you are making sense.

dadabe said
"Yes so it is and ecactly this is the bug: "The destructor of the temporary must not be called.""

Man, nobody knows who you are, you tell great stories, but all of these assumptions and Bug claims really destroys your credability.
dadabe said
"Yes are right about: the temporary object has to be destroyed.
But with free and not with delete, if the object is used."

Uh, if it was allocated with New then you release with delete, if malloc then free. Unfortunately you were dead wrong here.

dadabe said
"Why? Ok the final destruction involves calling the destructor, but not a temporary intermediate step, which only was performed, because the compiler developers didn't make the optimal implementation."

You are a pro bug finder solution guy, and you find bugs in languages you aren't even familiar with, then when the experts give you concrete reasoning, you have no choice but to fall back onto philisophical chit chatter to be or not to be.

dadabe said
"Maybe we first should argue more practical than technical? Because the discussion becomes a little bit too technically for beginners - oh not for me."

First, you ARE a beginner in C++. Second, you clearly don't get it up to this point. Third, if there were beginners following this thread you have done a great job of giving some of the worst info in a thread on this forum about C++ and how a compiler should work.

Then dadabe tells the "horse story"...

dadabe said
"You think, I don't understand, what an object is? What do you think about a GUI object Cat?"

No you don't, at least not in C++. How you've gotten this far into the discussion and had the answer solved in post two, then explained to you over and over in different terms and you still havent figured out the problem with your bug assumption is beyond me. Remember your bro boss: And then he said, he thinks it difficult, that people, who are not young any more, can learn something new.

dadabe said
"It's exactly, what I need. The temporary object is moved to it's destination. At the stack or whereever is only left an empty storage (without the object) and for this storage no destructor will be called!!! "

Do you even know how Move vs Copy works? Move transfers ownership of the memory from ObjectA to ObjectB, then ObjectA points to NULL, which is why when ObjectA is destructed, it doesn't free any memory that B is pointing to (over simplified so you can understand).
Copying ObjectA to ObjectB is this, ObjectB allocates new memory and copies what is in memory at the address pointed to by ObjectA into the memory location pointed to by ObjectB. Now ObjectA is destroyed, the memory allocated to A is freed, but B is is pointing to memory it owns, with the same values in that memory as A was before the copy was performed.

dadabe said
"cire wrote:
if you'd used a shared_ptr
Oh, I didn't know about such new things. It looks like using C++/CLI. C++/CLI works very fine.
And it's Standard Template Library.
Very nice!!!"


Clearly validating your expertise... come on man, we are just trying to help you understand the error in your bug logic.

dadabe said
"C++ is more secure: the compiler does it
But it's not simple: have to know much - the cases, where the compiler will do it implicitly and the cases where not - the C++ reference counts more than 1300 pages
And it causes also bugs: people don't now all cases."

You don't know all cases, this is clear, you don't even know the basic cases.

dadabe said (now 3 pages deep)
"I think I got it!"

About time. Now if you just left it at that, you would have made your bosses brother proud. But your ego was hurt, because you made all these incorrect assumptions and were proven incorrect and so you had to find Something to be right about.

dadabe said
"Sorry, now I saw my mistake - I red the specification more carefully. I'am just a beginner in C++, and it was me, who didn't understand the basics."

Yes!
"Open is still, wether it's correct or not correct, what the compiler does if we do it, how I did first."

Man, give it a rest, it's incorrect the way "how you did it first", the compiler is doing exactly as you told it to do (or didn't tell it to do because you didn't overload correctly).

dadabe said
"Problem partly solved with VC11 but maybe still a bug (linux g++) - also in VC11?
The problem is solved with the move assignment operator, available with VC11."

Well I thought you had it, you didn't, because this IS not the fix, it emulates the fix because it doesn't free the memory, it MOVES it, it's your incorrect implementation that makes copying blow up on temporary destruction, not the compiler.

dadabe said
"you are discussing like the specification would be the bible. Do you think and believe such definitions, like what a bug is?"

You have no technical response from here on out, just philisophically conceding you lack the technical knowledge on the topic, and refuse to let it rest.

dadabe said
"I know, what is a shallow and a deep copy."

No you didn't and I still think you don't, because you say that the Move operation partially fixes the problem. No, it emulates the fix because of your code, and because you don't see this, you don't understand a shallow and deep copy. A deep copy assignment operator FIXES your code as well as MOVE.

dadabe tells a story about his thinking...
dadabe tells the world how some people understand and some people just don't and that one day they will come to grips with reality and understand and say they understand, understand?
dadabe recollects some tales of his past...
dadabe tells us what he has learned.
"And I understood something, what the brother of my boss told me."

and goes on with
"I had thought, there were bugs in a software, which we would like to buy. And I wrote emails to this company and told, what I thought, and made assumptions."

WOW, come on, this is just bad etiquette. I hope you didn't make assumptions as far fetched as the ones you have made on this forum.

What I learned

- don't tell something - sure go ahead, give your reasoning's, not non related horses in stables talks
- ask questions - yes
- don't expect an answer - glass half full?
- don't discuss an answer - you are on a technical forum talking about tales of a wise man....
- say Thank You - good etiquette

dadabe said
"And then he said, he thinks it difficult, that people, who are not young any more, can learn something new."

Sounds like he is describing someone in this thread...

dadabe then goes on to tell a very enlightening story about his non C++ experience. Your right, it doesn't help your credibility on this bug topic.

You don't have to "like" any of the answers on this forum, but the people answering the questions genuinely want to help you out (Most of them).
Last edited on
by reading quite a lot of the first post, i feel a little bit twisted in my head... how come:

 
CatClass("UnusedCat");


do something like:

1
2
CatClass * pTemp = new CatClass("UnusedCat");
delete pTemp;


AFAIK, it doesn't deleted. it remains on the program, but it not accessed anymore, it just for one time used...

and

 
CatClass * pTemp = new CatClass("UnusedCat");


don't delete the pTemp, but you can delete it manually...

 
delete pTemp;


i mean, explicitly...

CMIIW
Topic archived. No new replies allowed.
Pages: 1234