Dialogue # 26: a Midsummer Night's Madness

zhaozj2021-02-16  50

Dialogue # 26: a Midsummer Night's Madness

"Well, let's talk, do you have a small meeting?"

I identified the timid sound from me. Kerry, new employees in our department are stood in my room. He is smart enough, but ... a man, some funny. I once told Weidi, but she just muttered, probably the issue of pots and pots.

"Yes, no problem," I turned to him. I don't have more experience in Kerry, but it is comfortable to make people feel comfortable. I am ready to throw me.

"What is the hotline number of our London office?"

I sighed. Become guidance experts are really troublesome. I wrote to him on the note.

"Thank you," he said while turning around. "I have to ask Bob's something."

Danger, Robinson! My heart mentioned the eyes. "Don't!" I am out of mouth.

Kerry is in the heart. "That is to say, don't bother him?" "I mean, um," I thought about it quickly ... I quickly thought. "Don't bother him. I am sure we can handle it."

"But Bob said that I should stay far away," Kerry said. "He said before leaving. If I have any questions, I should call him. He said, 'No matter what you do, you can ...'"

"Oh, look at time," I broke it. "London time has now taken off work. Bob should have left a long time."

"But there is now 3:30 now."

"Yes, this is Bob's getting time, I think." I said loudly, "Bob ... When he is in London, work time becomes early."

"Oh. Ok, I think this makes sense," Kerry did not be confident, but he was still sitting on my visitors.

"The problem is, I have a function of receiving the parameters of the indicator type," he said while writing on the whiteboard:

TYPEDEF T * TPTR;

Void f (const tptr t)

{

* T = t (); // Don't Want this, But it's allowed

}

"In the function body, I can modify T, even if I declare it is const. I also tried TPTR Const T, but it didn't work. If I don't use Typedef, I know, I can write const t * t, That is what I want. "

"Ah," I thought. I know that I have encountered this problem before.

But where is it? What time? "Well, Typedef and Hong's text is not exactly consistent. I can't remember all details, but I am sure that when the type is added to constraint, its behavior is the same as your expectations." I have revised the code slightly:

Void F (TPTR Const T) // STILL Means T * Const

Kerry aimed at the new code. "But TPTR CONST T and Const TPTR T are not the same. Isn't it?"

A new voice says: "No! Nothing."

I vibrate for the sound of Guru after the body. Kerry screamed from the chair jumping up. Guru continued quietly, close the thickens in his hand, and the reaction to our reaction was not seen: "Tell me, what is the difference between Int Const I and Const Int I?"

Kerry's eyes were very big - very large, so that I was curious about Bob to describe Guru. Guru did not seem to notice his treasure.

I think it is best not to participate in Guru's behavior: "They are the same thing. Isn't it, Kerry?" I prompt. Kerry just nodded and didn't speak. Guru frowned. "So, if constinary is equivalent, it is expected that TPTR Const and Const TPTR are different. Are you thinking so? Well? And you should not think."

"Yes, I am explaining that part," I plugged a mouth. "Well, Kerry, in this code, what is constant?" I wrote:

Const Int i; // or int const i;

"INT," Kerry said slowly. This simple problem allowed him to recover calm.

"Okay," I nodded. "Now in this code, what is constant, even if T is a TypedEf?" I wrote:

Const T T; // OR T CONST T

"T object," Kerry replied, now there is confident.

"Okay. Now in this code, what is constant?" I wrote:

Const TPTR T; // or TPTR Const T

"That ..." Kerry swallowed. "Oh .tptr?"

"But TPTR is characterized by a composite type, and const is only part of this type. The pointer itself is constant; this is the same as T * const. Now, there is a little bit: In this code, what is constant ? "I wrote:

Const T * t; // or t const * t

"That ... the object points to," he called out.

"Yes," I am sure, and put down the pen. "This is the difference between Const TPTR and Const T *."

Guru took one hand on my shoulder and took a topic: "In fact, this is some of the reasons why the prophet [1] makes the following recommendations: Under the premise of not changing the meaning of the stated, put the const key On the right side as possible. Then you open Typedef as an evil macro in your heart, "she taught," to get the right meaning. "

"Yes, but I always feel more embarrassment," I complained. "I like to declare 'const IPTR', so when I read it, I can read the 'constant INT pointer iptr'. Almost everyone and all books are written in this. In addition, that way Feeling comparison. "

"拗口?" Guru raised his eyebrows. "Although we are neither recommending to oppose the style of 'Const on the right', this is really good. It makes it easy to read the statement."

"How?" Kerry asked.

"Read it by compiler, you have to do this. You actually say that 'iptr is a pointer to const, from right to left, is' int const * iptr;' meaning."

"But, then how do I declare my function so that the T object is really constant?" Kerry returned to his initial problem.

"Ah, my child is very simple." Guru wrote:

Void f (const t * t)

"But I really want to use typedf," Kerry oppose. "

"Ah, wipe the board. If you must use TypeDef, you will define a TypedEf for the required const t:"

Typedef const t * tcptr;

Void F (TCPTR T)

"But still have to be careful," Guru pointed to malnstening, "We have found that using Typedef to generate a pointer value very small. Because of the const defects discussed here, you must provide two separate typedef. Such typedef hyperplasia And it is very small in the sense that it will only cause confusion. There is no value. "

Guru opened her book and turned and left. "The confusion is a programmed dark side. Too many typedef, weak naming - these are caused by ..." Her voice disappeared with a corner.

I saw Kerry. He stared at me and he would stop.

"Don't worry," I comforted him, "You will get used to her. She is really an extremely excellent programmer." Kerry blinked, Zhang opened again, and it took place. I shrugged and went back to work.

[Note]

[1] NOTABLY DAN SAKS.

转载请注明原文地址:https://www.9cbs.com/read-26718.html

New Post(0)