Difference between revisions of "User:J Lipscomb"
From eLinux.org
J Lipscomb (Talk | contribs) |
J Lipscomb (Talk | contribs) m |
||
| Line 12: | Line 12: | ||
|- | |- | ||
|- | |- | ||
| − | | 2- | + | | 2-21 |
| − | | | + | | Hello World, Embedded Style |
| − | + | ||
| <pre> | | <pre> | ||
| − | + | #include <stdio.h> | |
| + | |||
| + | int bss_var; /* Uninitialized global variable */ | ||
| + | |||
| + | int data_var = 1; /* Initialized global variable */ | ||
| + | |||
| + | int main(int argc, char **argv) | ||
| + | { | ||
| + | void *stack_var; /* Local variable on the stack */ | ||
| + | |||
| + | stack_var = (void *)main; /* Don't let the compiler */ | ||
| + | /* optimize it out */ | ||
| + | |||
| + | printf("Hello, World! Main is executing at %p\n", stack_var); | ||
| + | printf("This address (%p) is in our stack frame\n", &stack_var); | ||
| + | |||
| + | /* bss section contains uninitialized data */ | ||
| + | printf("This address (%p) is in our bss section\n", &bss_var); | ||
| + | |||
| + | /* data section contains initializated data */ | ||
| + | printf("This address (%p) is in our data section\n", &data_var); | ||
| + | |||
| + | return 0; | ||
| + | } | ||
</pre> | </pre> | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
Revision as of 19:39, 21 March 2010
I am currently an Electrical Engineering undergraduate student at Rose-Hulman Institute of Technology in Terre Haute, Indiana.
Chapter 2
| Number | Page | Caption | Listing |
|---|---|---|---|
| 2-21 | Hello World, Embedded Style |
#include <stdio.h>
int bss_var; /* Uninitialized global variable */
int data_var = 1; /* Initialized global variable */
int main(int argc, char **argv)
{
void *stack_var; /* Local variable on the stack */
stack_var = (void *)main; /* Don't let the compiler */
/* optimize it out */
printf("Hello, World! Main is executing at %p\n", stack_var);
printf("This address (%p) is in our stack frame\n", &stack_var);
/* bss section contains uninitialized data */
printf("This address (%p) is in our bss section\n", &bss_var);
/* data section contains initializated data */
printf("This address (%p) is in our data section\n", &data_var);
return 0;
}
|