tests and fixes
This commit is contained in:
		
							parent
							
								
									4dc291b27e
								
							
						
					
					
						commit
						d1d1c88934
					
				
					 2 changed files with 18 additions and 11 deletions
				
			
		
							
								
								
									
										18
									
								
								demo/add.c
									
										
									
									
									
								
							
							
						
						
									
										18
									
								
								demo/add.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -1,11 +1,18 @@
 | 
			
		|||
int printf(const char format[], ...);
 | 
			
		||||
int scanf(const char format[], ...);
 | 
			
		||||
int putchar(int ch);
 | 
			
		||||
 | 
			
		||||
int* p;
 | 
			
		||||
void should_be(int expected, int actual) {
 | 
			
		||||
    if (expected != actual) {
 | 
			
		||||
        printf("Expected %d, but got %d\n", expected, actual);
 | 
			
		||||
    } else {
 | 
			
		||||
        printf("Passed\n");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int* p = 0;
 | 
			
		||||
int f1() {
 | 
			
		||||
    int a = 1;
 | 
			
		||||
    return *(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(p))))))))))); // a[10]
 | 
			
		||||
    return *(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(p))))))))))); // p[10]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -13,5 +20,8 @@ int main() {
 | 
			
		|||
    int a[15];
 | 
			
		||||
    p = a;
 | 
			
		||||
    for (int i = 0; i < 15; a[i] = i, ++i);
 | 
			
		||||
    return f1();
 | 
			
		||||
    p -= 5;
 | 
			
		||||
    should_be(5, f1());
 | 
			
		||||
    should_be(5, a - p);
 | 
			
		||||
    should_be(10, 5);
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue