Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
f1ce9470
Commit
f1ce9470
authored
Jun 02, 2011
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved how code blocks are displayed.
parent
2952abbf
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
17 deletions
+36
-17
howto_contribute.xml
docs/docs/howto_contribute.xml
+14
-15
intro.xml
docs/docs/intro.xml
+2
-2
stylesheet.xsl
docs/docs/stylesheet.xsl
+20
-0
No files found.
docs/docs/howto_contribute.xml
View file @
f1ce9470
...
...
@@ -255,8 +255,9 @@
<p>
Most importantly, it is impossible to validate the state of a pointer. Consider two
functions:
<blockquote><tt>
double compute_sum_of_array_elements(const double* array, int array_size);
<br/>
double compute_sum_of_array_elements(const std::vector
<
double
>&
array);
</tt></blockquote>
<code_box>
double compute_sum_of_array_elements(const double* array, int array_size);
double compute_sum_of_array_elements(const std::vector
<
double
>&
array);
</code_box>
The first function is inherently unsafe. If the user accidentally passes in an invalid pointer
or sets the size argument incorrectly then their program may crash and this will turn into a
...
...
@@ -294,7 +295,7 @@
<li>
<h3>
Don't use stack based arrays.
</h3>
<ul><p>
A stack based array, or C style array, is an array declared like this:
<
blockquote><tt>
int array[200];
</tt></blockquote
>
<
code_box>
int array[200];
</code_box
>
Most of my criticisms of pointers also apply to stack based arrays. In particular,
if you are passing a stack based array to a function then that means you are probably
using functions similar to the unsafe compute_sum_of_array_elements() example above.
...
...
@@ -310,14 +311,13 @@
checking such as the
<a
href=
"containers.html#std_vector_c"
>
std_vector_c
</a>
.
</p>
<p>
Consider the following two bits of code:
<
pre
>
for (int i = 0; i
<
array_size; ++i)
<
code_box
>
for (int i = 0; i
<
array_size; ++i)
my_c_array[i] = 4;
for (int i = 0; i
<
my_std_vector.size(); ++i)
for (int i = 0; i
<
my_std_vector.size(); ++i)
my_std_vector[i] = 4;
</pre>
</code_box>
The second loop clearly doesn't overflow the bounds of the my_std_vector. On the other
hand, just by looking at the code in the first loop, we can not tell if it overflows
my_c_array. We have to assume that array_size is the appropriate constant but we could be wrong.
...
...
@@ -513,13 +513,12 @@ Dynamic Libraries in C++</a>, and
into either big or little endian byte order and then write them to an output stream.
You could do this using code similar to the following:
<pre>
dlib::
<a
href=
"other.html#byte_orderer"
>
byte_orderer
</a>
::kernel_1a bo;
...
bo.host_to_big(my_uint);
my_out_stream.write((char*)
&
my_uint, sizeof(my_uint));
...
</pre>
<code_box>
dlib::
<a
href=
"other.html#byte_orderer"
>
byte_orderer
</a>
::kernel_1a bo;
...
bo.host_to_big(my_uint);
my_out_stream.write((char*)
&
my_uint, sizeof(my_uint));
...
</code_box>
<p>
There are three important things to understand about this process. First, you need
...
...
docs/docs/intro.xml
View file @
f1ce9470
...
...
@@ -153,7 +153,7 @@
An example will make it clear.
<
pre
><font
color=
'#3333FF'
>
int
</font>
<b>
funct
</b><font
face=
"Lucida Console"
>
(
</font>
<
code_box
><font
color=
'#3333FF'
>
int
</font>
<b>
funct
</b><font
face=
"Lucida Console"
>
(
</font>
<font
color=
'#3333FF'
>
int
</font>
&
something
<font
face=
"Lucida Console"
>
);
</font>
<font
color=
'#009900'
>
/*!
...
...
@@ -164,7 +164,7 @@
- #funct() == something
- #something == something + 1
!*/
</font>
</pre
>
</code_box
>
This says that funct() requires that "something" be greater than 4, that funct() will increment "something"
by 1, and funct() returns the original value of something. It also says that
...
...
docs/docs/stylesheet.xsl
View file @
f1ce9470
...
...
@@ -221,6 +221,21 @@
margin: 0.5em;
}
.code_box
{
color: black;
margin: 1em 0.25in;
padding: 0.5em;
background: rgb(240,240,240);
border-top: black dotted 1px;
border-left: black dotted 1px;
border-right: black solid 2px;
border-bottom: black solid 2px;
}
.bdotted {border-bottom: 1px dotted}
.bdashed {border-bottom: 1px dashed}
.bsolid {border-bottom: 1px solid}
...
...
@@ -1251,6 +1266,11 @@
</div>
</xsl:template>
<!-- ************************************************************************* -->
<xsl:template
match=
"code_box"
>
<pre
class=
"code_box"
><xsl:apply-templates/></pre>
</xsl:template>
<!-- ************************************************************************* -->
<!-- ************************************************************************* -->
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment