-关于《c专家编程》的读书笔记
—————————————————
试验目的1,比较指针与数组取值方式的异同。2,比较指针与数组作为函数参数时候的异同。
最近在复习c(c++)语言里面的复杂声明,这个东西真是麻烦的紧啊。
准备在公司内部的reading group做的演示。
p19,两个操作数都是指向有限定符或者无限定符的相容类型的指针。左边指针必须具有所有右边指针所指向类型的全部限定符。
函数原型void foo(const char** p)
当我们使用这样的调用,会有警告:
char* p = NULL; foo(&p);
但是当函数原型是void foo2(const char* p),
如下调用就没有问题:
char* p = NULL; foo(p);
原因很简单,对于const char** p来说,我们一层层剥掉*,就是这样
形参p是一个指针,指向const char*类型。
当我们使用char* p = NULL; foo(&p);这样形式,实参p是一个指针,指向char*类型。
他两个都是没有限定符的,限定符const都是被指向的类型所使用了。
所以,第一种调用不成功。但是对于第二种来说,就是成功的,因为形参具有所有实参的限定符(形参有const,实参没有)。
另外,在ubuntu下使用gcc编译器,会有这个警告,但是vc2008没有,不知道是不是vc2008项目配置错了。
You could use the macro function to add function header that could use by doxygen.
It is tested in Visual studio 2008.
Sub FunctionHeader()
Dim objEditPt As EditPoint
Dim currentLine As Integer
Dim endline As Integer
Dim findString As String
Dim findString2 As String
Dim firstPosition As Integer
Dim voidPosition As Integer
Dim BoolPosition As Integer
Dim PtrPosition As Integer
Dim lastPosition As Integer
objEditPt = DTE.ActiveDocument.Selection.ActivePoint.CreateEditPoint
currentLine = objEditPt.Line
objEditPt.EndOfDocument()
endLine = objEditPt.Line
If (endLine > currentLine + 50) Then
endLine = currentLine + 50
End If
findString = objEditPt.GetLines(currentLine, endLine)
‘get params with “(” and “)”
findString2 = “”
Dim strList As New System.Collections.ArrayList
Dim findVoid As Boolean = False
Dim findBool As Boolean = False
Dim findPtr As Boolean = False
firstPosition = InStr(findString, “(“)
voidPosition = InStr(findString, “void”)
BoolPosition = InStr(findString, “BOOL “)
PtrPosition = InStr(findString, “* “)
If (firstPosition >= 1) Then
If (voidPosition >= 1 And voidPosition < firstPosition) Then
findVoid = True
End If
If (PtrPosition >= 1 And PtrPosition < firstPosition) Then
findPtr = True
End If
If (BoolPosition >= 1 And BoolPosition < firstPosition) Then
findBool = True
End If
lastPosition = InStr(firstPosition, findString, “)”)
If (lastPosition >= firstPosition) Then
findString2 = Mid(findString, firstPosition + 1, lastPosition – firstPosition – 1)
strList.AddRange(findString2.Split(“,”c))
End If
End If
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = “/**”
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = “* ”
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = “* ”
DTE.ActiveDocument.Selection.NewLine()
Dim listCount As Integer
Dim newString As String
listCount = strList.Count
For Each stringElement In strList
stringElement = Replace(stringElement, vbCr, “”)
stringElement = Replace(stringElement, vbLf, “”)
stringElement = Replace(stringElement, vbTab, ” “)
stringElement = Trim(stringElement)
If stringElement.Length <= 0 Then
Continue For
End If
Dim bAsIn = “[in] ”
If InStr(stringElement, “*”) Then
bAsIn = “[out] ”
End If
newString = “* @param ” + bAsIn + stringElement + ” : ”
DTE.ActiveDocument.Selection.Text = newString
DTE.ActiveDocument.Selection.NewLine()
Next
DTE.ActiveDocument.Selection.Text = “* ”
DTE.ActiveDocument.Selection.NewLine()
If findVoid Then
DTE.ActiveDocument.Selection.Text = “* @return void.”
DTE.ActiveDocument.Selection.NewLine()
ElseIf findBool Then
DTE.ActiveDocument.Selection.Text = “* @return True success;”
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = ” False, failed;”
DTE.ActiveDocument.Selection.NewLine()
ElseIf findPtr Then
DTE.ActiveDocument.Selection.Text = “* @return valid pointer; or NULL.”
DTE.ActiveDocument.Selection.NewLine()
Else
DTE.ActiveDocument.Selection.Text = “* @return S_OK : the processing completed successfully;”
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = “* E_POINTER : a NULL pointer parameter was passed;”
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = “* E_FAIL : Some other failure occurred;”
DTE.ActiveDocument.Selection.NewLine()
End If
DTE.ActiveDocument.Selection.Text = “* ”
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = “*/”
End Sub