Data update
This commit is contained in:
parent
8e4e15fa56
commit
72eb4943cb
1853 changed files with 35514 additions and 9441 deletions
|
|
@ -1,3 +1,3 @@
|
|||
if(a=b){} //assigns to "a" the value of "b". Then, if "a" is nonzero, the code in the curly braces is run.
|
||||
|
||||
if(a==b){} //runs the code in the curly braces if and only if the value of "a" equals the value of "b".
|
||||
if (a=b) {
|
||||
...; /* this is run if b is non-zero */
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,2 @@
|
|||
int main()
|
||||
{
|
||||
int x = 3;
|
||||
int y = 5;
|
||||
int z = 7;
|
||||
printf("%d %d %d %x %x",x,y,z); //on an Intel cpu the first %x reveals %%ebp and the second reveals the return address.)
|
||||
}
|
||||
myArray[40];
|
||||
int x = gotcha(&myArray[0]);
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
(let numbers [1 2 3 4]
|
||||
maximum (max numbers)) ;should be (... max numbers)
|
||||
(+ maximum 5)
|
||||
int foo(char buf[],int length){}
|
||||
|
||||
int main()
|
||||
{
|
||||
char myArray[30];
|
||||
int j = foo(myArray,sizeof(myArray)); //passes 30 as the length parameter.
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,2 +1,4 @@
|
|||
(mock + (fn a b ((unmocked +) a b 1)))
|
||||
(+ 2 3)
|
||||
int x = 3;
|
||||
int y = 5;
|
||||
printf("%d %d %x\n",x,y); /* this may crash or print undefined values after 3 5 */
|
||||
printf("testing %n\n"); /* this writes the int value 8 to an undefined location */
|
||||
|
|
|
|||
7
Task/Gotchas/C/gotchas-13.c
Normal file
7
Task/Gotchas/C/gotchas-13.c
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
void
|
||||
say_hello(const char *name) /* assume name is something the user entered */
|
||||
{
|
||||
printf("hello ");
|
||||
printf(name); /* the name entered could be "%s" or "%n" or something */
|
||||
printf("\n");
|
||||
}
|
||||
|
|
@ -1 +1,3 @@
|
|||
int foo[4] = {4,8,12,16};
|
||||
if (a==b) {
|
||||
...; /* this is run if a and b are equal */
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
int foo[4] = {4,8,12,16};
|
||||
int x = foo[0]; //x = 4
|
||||
int y = foo[3]; //y = 16
|
||||
int z = foo[4]; //z = ?????????
|
||||
if ( (a=b) ) { /* this shows that an assignment was intended */
|
||||
...;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1 @@
|
|||
int foo()
|
||||
{
|
||||
char bar[20];
|
||||
return sizeof(bar);
|
||||
}
|
||||
int foo[4] = { 4, 8, 12, 16 };
|
||||
|
|
|
|||
|
|
@ -1,7 +1,4 @@
|
|||
int foo()
|
||||
{
|
||||
#define size_of_bar 20 //the sizeof operator is the same as doing this essentially.
|
||||
|
||||
char bar[size_of_bar];
|
||||
return size_of_bar;
|
||||
}
|
||||
int foo[4] = { 4, 8, 12, 16 };
|
||||
int x = foo[0]; /* x = 4 */
|
||||
int y = foo[3]; /* y = 16 */
|
||||
int z = foo[4]; /* z contains whatever was after foo[3] in memory */
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
int gotcha(char bar[])
|
||||
{
|
||||
return sizeof(bar);
|
||||
int i;
|
||||
int squarenums[10];
|
||||
for (i=0; i<=10; i++) {
|
||||
squarenums[i] = i * i;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,2 +1,5 @@
|
|||
myArray[40];
|
||||
int x = gotcha(myArray);
|
||||
int foo()
|
||||
{
|
||||
char bar[20];
|
||||
return sizeof(bar); /* returns 20 as expected */
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,2 +1,4 @@
|
|||
myArray[40];
|
||||
int x = gotcha(&myArray[0]);
|
||||
int gotcha(char bar[]) /* could have been: int gotcha(char *bar) */
|
||||
{
|
||||
return sizeof(bar); /* returns the size of a pointer to char, probably 4 on 32-bit systems and 8 on 64-bit systems */
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,2 @@
|
|||
int foo(char buf[],int length){}
|
||||
|
||||
int main()
|
||||
{
|
||||
char myArray[30];
|
||||
int j = foo(myArray,sizeof(myArray)); //passes 30 as the length parameter.
|
||||
}
|
||||
char myArray[40];
|
||||
int x = gotcha(myArray);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,15 @@
|
|||
; this takes two bytes, it is slower on some processors but faster or the same on others
|
||||
label:
|
||||
;loop body goes here
|
||||
DEC ECX
|
||||
JNZ label
|
||||
loop label
|
||||
|
||||
; this takes three bytes but is slower on some processors
|
||||
label:
|
||||
dec ecx
|
||||
jnz label
|
||||
|
||||
; this is takes five bytes and is potentially faster than the above
|
||||
label:
|
||||
sub ecx,1
|
||||
jnz label
|
||||
|
||||
; there is also a two-byte jecxz instruction but no jecxnz
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue