09.C语言:预处理(宏定义)、字节序、地址对齐

一、预处理

  

1 预处理
2 gcc -E Hello.c -o hello.i
3 编译
4 gcc -S hello.i -o hello.s
5 汇编
6 gcc -c hello.s -o hello.o
7 链接
8 gcc hello.o -o hello
Makefile
  1 # 1 "hello.c"
  2 # 1 "<built-in>"
  3 # 1 "<command-line>"
  4 # 1 "/usr/include/stdc-predef.h" 1 3 4
  5 # 1 "<command-line>" 2
  6 # 1 "hello.c"
  7 
  8 
  9 
 10 
 11 
 12 
 13 
 14 # 1 "/usr/include/stdio.h" 1 3 4
 15 # 27 "/usr/include/stdio.h" 3 4
 16 # 1 "/usr/include/features.h" 1 3 4
 17 # 374 "/usr/include/features.h" 3 4
 18 # 1 "/usr/include/i386-linux-gnu/sys/cdefs.h" 1 3 4
 19 # 385 "/usr/include/i386-linux-gnu/sys/cdefs.h" 3 4
 20 # 1 "/usr/include/i386-linux-gnu/bits/wordsize.h" 1 3 4
 21 # 386 "/usr/include/i386-linux-gnu/sys/cdefs.h" 2 3 4
 22 # 375 "/usr/include/features.h" 2 3 4
 23 # 398 "/usr/include/features.h" 3 4
 24 # 1 "/usr/include/i386-linux-gnu/gnu/stubs.h" 1 3 4
 25 
 26 
 27 
 28 
 29 
 30 
 31 # 1 "/usr/include/i386-linux-gnu/gnu/stubs-32.h" 1 3 4
 32 # 8 "/usr/include/i386-linux-gnu/gnu/stubs.h" 2 3 4
 33 # 399 "/usr/include/features.h" 2 3 4
 34 # 28 "/usr/include/stdio.h" 2 3 4
 35 
 36 
 37 
 38 
 39 
 40 # 1 "/usr/lib/gcc/i686-linux-gnu/4.8/include/stddef.h" 1 3 4
 41 # 212 "/usr/lib/gcc/i686-linux-gnu/4.8/include/stddef.h" 3 4
 42 typedef unsigned int size_t;
 43 # 34 "/usr/include/stdio.h" 2 3 4
 44 
 45 # 1 "/usr/include/i386-linux-gnu/bits/types.h" 1 3 4
 46 # 27 "/usr/include/i386-linux-gnu/bits/types.h" 3 4
 47 # 1 "/usr/include/i386-linux-gnu/bits/wordsize.h" 1 3 4
 48 # 28 "/usr/include/i386-linux-gnu/bits/types.h" 2 3 4
 49 
 50 
 51 typedef unsigned char __u_char;
 52 typedef unsigned short int __u_short;
 53 typedef unsigned int __u_int;
 54 typedef unsigned long int __u_long;
 55 
 56 
 57 typedef signed char __int8_t;
 58 typedef unsigned char __uint8_t;
 59 typedef signed short int __int16_t;
 60 typedef unsigned short int __uint16_t;
 61 typedef signed int __int32_t;
 62 typedef unsigned int __uint32_t;
 63 
 64 
 65 
 66 
 67 __extension__ typedef signed long long int __int64_t;
 68 __extension__ typedef unsigned long long int __uint64_t;
 69 
 70 
 71 
 72 
 73 
 74 
 75 
 76 __extension__ typedef long long int __quad_t;
 77 __extension__ typedef unsigned long long int __u_quad_t;
 78 # 121 "/usr/include/i386-linux-gnu/bits/types.h" 3 4
 79 # 1 "/usr/include/i386-linux-gnu/bits/typesizes.h" 1 3 4
 80 # 122 "/usr/include/i386-linux-gnu/bits/types.h" 2 3 4
 81 
 82 
 83 __extension__ typedef __u_quad_t __dev_t;
 84 __extension__ typedef unsigned int __uid_t;
 85 __extension__ typedef unsigned int __gid_t;
 86 __extension__ typedef unsigned long int __ino_t;
 87 __extension__ typedef __u_quad_t __ino64_t;
 88 __extension__ typedef unsigned int __mode_t;
 89 __extension__ typedef unsigned int __nlink_t;
 90 __extension__ typedef long int __off_t;
 91 __extension__ typedef __quad_t __off64_t;
 92 __extension__ typedef int __pid_t;
 93 __extension__ typedef struct { int __val[2]; } __fsid_t;
 94 __extension__ typedef long int __clock_t;
 95 __extension__ typedef unsigned long int __rlim_t;
 96 __extension__ typedef __u_quad_t __rlim64_t;
 97 __extension__ typedef unsigned int __id_t;
 98 __extension__ typedef long int __time_t;
 99 __extension__ typedef unsigned int __useconds_t;
100 __extension__ typedef long int __suseconds_t;
101 
102 __extension__ typedef int __daddr_t;
103 __extension__ typedef int __key_t;
104 
105 
106 __extension__ typedef int __clockid_t;
107 
108 
109 __extension__ typedef void * __timer_t;
110 
111 
112 __extension__ typedef long int __blksize_t;
113 
114 
115 
116 
117 __extension__ typedef long int __blkcnt_t;
118 __extension__ typedef __quad_t __blkcnt64_t;
119 
120 
121 __extension__ typedef unsigned long int __fsblkcnt_t;
122 __extension__ typedef __u_quad_t __fsblkcnt64_t;
123 
124 
125 __extension__ typedef unsigned long int __fsfilcnt_t;
126 __extension__ typedef __u_quad_t __fsfilcnt64_t;
127 
128 
129 __extension__ typedef int __fsword_t;
130 
131 __extension__ typedef int __ssize_t;
132 
133 
134 __extension__ typedef long int __syscall_slong_t;
135 
136 __extension__ typedef unsigned long int __syscall_ulong_t;
137 
138 
139 
140 typedef __off64_t __loff_t;
141 typedef __quad_t *__qaddr_t;
142 typedef char *__caddr_t;
143 
144 
145 __extension__ typedef int __intptr_t;
146 
147 
148 __extension__ typedef unsigned int __socklen_t;
149 # 36 "/usr/include/stdio.h" 2 3 4
150 # 44 "/usr/include/stdio.h" 3 4
151 struct _IO_FILE;
152 
153 
154 
155 typedef struct _IO_FILE FILE;
156 
157 
158 
159 
160 
161 # 64 "/usr/include/stdio.h" 3 4
162 typedef struct _IO_FILE __FILE;
163 # 74 "/usr/include/stdio.h" 3 4
164 # 1 "/usr/include/libio.h" 1 3 4
165 # 31 "/usr/include/libio.h" 3 4
166 # 1 "/usr/include/_G_config.h" 1 3 4
167 # 15 "/usr/include/_G_config.h" 3 4
168 # 1 "/usr/lib/gcc/i686-linux-gnu/4.8/include/stddef.h" 1 3 4
169 # 16 "/usr/include/_G_config.h" 2 3 4
170 
171 
172 
173 
174 # 1 "/usr/include/wchar.h" 1 3 4
175 # 82 "/usr/include/wchar.h" 3 4
176 typedef struct
177 {
178   int __count;
179   union
180   {
181 
182     unsigned int __wch;
183 
184 
185 
186     char __wchb[4];
187   } __value;
188 } __mbstate_t;
189 # 21 "/usr/include/_G_config.h" 2 3 4
190 typedef struct
191 {
192   __off_t __pos;
193   __mbstate_t __state;
194 } _G_fpos_t;
195 typedef struct
196 {
197   __off64_t __pos;
198   __mbstate_t __state;
199 } _G_fpos64_t;
200 # 32 "/usr/include/libio.h" 2 3 4
201 # 49 "/usr/include/libio.h" 3 4
202 # 1 "/usr/lib/gcc/i686-linux-gnu/4.8/include/stdarg.h" 1 3 4
203 # 40 "/usr/lib/gcc/i686-linux-gnu/4.8/include/stdarg.h" 3 4
204 typedef __builtin_va_list __gnuc_va_list;
205 # 50 "/usr/include/libio.h" 2 3 4
206 # 144 "/usr/include/libio.h" 3 4
207 struct _IO_jump_t; struct _IO_FILE;
208 # 154 "/usr/include/libio.h" 3 4
209 typedef void _IO_lock_t;
210 
211 
212 
213 
214 
215 struct _IO_marker {
216   struct _IO_marker *_next;
217   struct _IO_FILE *_sbuf;
218 
219 
220 
221   int _pos;
222 # 177 "/usr/include/libio.h" 3 4
223 };
224 
225 
226 enum __codecvt_result
227 {
228   __codecvt_ok,
229   __codecvt_partial,
230   __codecvt_error,
231   __codecvt_noconv
232 };
233 # 245 "/usr/include/libio.h" 3 4
234 struct _IO_FILE {
235   int _flags;
236 
237 
238 
239 
240   char* _IO_read_ptr;
241   char* _IO_read_end;
242   char* _IO_read_base;
243   char* _IO_write_base;
244   char* _IO_write_ptr;
245   char* _IO_write_end;
246   char* _IO_buf_base;
247   char* _IO_buf_end;
248 
249   char *_IO_save_base;
250   char *_IO_backup_base;
251   char *_IO_save_end;
252 
253   struct _IO_marker *_markers;
254 
255   struct _IO_FILE *_chain;
256 
257   int _fileno;
258 
259 
260 
261   int _flags2;
262 
263   __off_t _old_offset;
264 
265 
266 
267   unsigned short _cur_column;
268   signed char _vtable_offset;
269   char _shortbuf[1];
270 
271 
272 
273   _IO_lock_t *_lock;
274 # 293 "/usr/include/libio.h" 3 4
275   __off64_t _offset;
276 # 302 "/usr/include/libio.h" 3 4
277   void *__pad1;
278   void *__pad2;
279   void *__pad3;
280   void *__pad4;
281   size_t __pad5;
282 
283   int _mode;
284 
285   char _unused2[15 * sizeof (int) - 4 * sizeof (void *) - sizeof (size_t)];
286 
287 };
288 
289 
290 typedef struct _IO_FILE _IO_FILE;
291 
292 
293 struct _IO_FILE_plus;
294 
295 extern struct _IO_FILE_plus _IO_2_1_stdin_;
296 extern struct _IO_FILE_plus _IO_2_1_stdout_;
297 extern struct _IO_FILE_plus _IO_2_1_stderr_;
298 # 338 "/usr/include/libio.h" 3 4
299 typedef __ssize_t __io_read_fn (void *__cookie, char *__buf, size_t __nbytes);
300 
301 
302 
303 
304 
305 
306 
307 typedef __ssize_t __io_write_fn (void *__cookie, const char *__buf,
308      size_t __n);
309 
310 
311 
312 
313 
314 
315 
316 typedef int __io_seek_fn (void *__cookie, __off64_t *__pos, int __w);
317 
318 
319 typedef int __io_close_fn (void *__cookie);
320 # 390 "/usr/include/libio.h" 3 4
321 extern int __underflow (_IO_FILE *);
322 extern int __uflow (_IO_FILE *);
323 extern int __overflow (_IO_FILE *, int);
324 # 434 "/usr/include/libio.h" 3 4
325 extern int _IO_getc (_IO_FILE *__fp);
326 extern int _IO_putc (int __c, _IO_FILE *__fp);
327 extern int _IO_feof (_IO_FILE *__fp) __attribute__ ((__nothrow__ , __leaf__));
328 extern int _IO_ferror (_IO_FILE *__fp) __attribute__ ((__nothrow__ , __leaf__));
329 
330 extern int _IO_peekc_locked (_IO_FILE *__fp);
331 
332 
333 
334 
335 
336 extern void _IO_flockfile (_IO_FILE *) __attribute__ ((__nothrow__ , __leaf__));
337 extern void _IO_funlockfile (_IO_FILE *) __attribute__ ((__nothrow__ , __leaf__));
338 extern int _IO_ftrylockfile (_IO_FILE *) __attribute__ ((__nothrow__ , __leaf__));
339 # 464 "/usr/include/libio.h" 3 4
340 extern int _IO_vfscanf (_IO_FILE * __restrict, const char * __restrict,
341    __gnuc_va_list, int *__restrict);
342 extern int _IO_vfprintf (_IO_FILE *__restrict, const char *__restrict,
343     __gnuc_va_list);
344 extern __ssize_t _IO_padn (_IO_FILE *, int, __ssize_t);
345 extern size_t _IO_sgetn (_IO_FILE *, void *, size_t);
346 
347 extern __off64_t _IO_seekoff (_IO_FILE *, __off64_t, int, int);
348 extern __off64_t _IO_seekpos (_IO_FILE *, __off64_t, int);
349 
350 extern void _IO_free_backup_area (_IO_FILE *) __attribute__ ((__nothrow__ , __leaf__));
351 # 75 "/usr/include/stdio.h" 2 3 4
352 
353 
354 
355 
356 typedef __gnuc_va_list va_list;
357 # 90 "/usr/include/stdio.h" 3 4
358 typedef __off_t off_t;
359 # 102 "/usr/include/stdio.h" 3 4
360 typedef __ssize_t ssize_t;
361 
362 
363 
364 
365 
366 
367 
368 typedef _G_fpos_t fpos_t;
369 
370 
371 
372 
373 # 164 "/usr/include/stdio.h" 3 4
374 # 1 "/usr/include/i386-linux-gnu/bits/stdio_lim.h" 1 3 4
375 # 165 "/usr/include/stdio.h" 2 3 4
376 
377 
378 
379 extern struct _IO_FILE *stdin;
380 extern struct _IO_FILE *stdout;
381 extern struct _IO_FILE *stderr;
382 
383 
384 
385 
386 
387 
388 
389 extern int remove (const char *__filename) __attribute__ ((__nothrow__ , __leaf__));
390 
391 extern int rename (const char *__old, const char *__new) __attribute__ ((__nothrow__ , __leaf__));
392 
393 
394 
395 
396 extern int renameat (int __oldfd, const char *__old, int __newfd,
397        const char *__new) __attribute__ ((__nothrow__ , __leaf__));
398 
399 
400 
401 
402 
403 
404 
405 
406 extern FILE *tmpfile (void) ;
407 # 209 "/usr/include/stdio.h" 3 4
408 extern char *tmpnam (char *__s) __attribute__ ((__nothrow__ , __leaf__)) ;
409 
410 
411 
412 
413 
414 extern char *tmpnam_r (char *__s) __attribute__ ((__nothrow__ , __leaf__)) ;
415 # 227 "/usr/include/stdio.h" 3 4
416 extern char *tempnam (const char *__dir, const char *__pfx)
417      __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__malloc__)) ;
418 
419 
420 
421 
422 
423 
424 
425 
426 extern int fclose (FILE *__stream);
427 
428 
429 
430 
431 extern int fflush (FILE *__stream);
432 
433 # 252 "/usr/include/stdio.h" 3 4
434 extern int fflush_unlocked (FILE *__stream);
435 # 266 "/usr/include/stdio.h" 3 4
436 
437 
438 
439 
440 
441 
442 extern FILE *fopen (const char *__restrict __filename,
443       const char *__restrict __modes) ;
444 
445 
446 
447 
448 extern FILE *freopen (const char *__restrict __filename,
449         const char *__restrict __modes,
450         FILE *__restrict __stream) ;
451 # 295 "/usr/include/stdio.h" 3 4
452 
453 # 306 "/usr/include/stdio.h" 3 4
454 extern FILE *fdopen (int __fd, const char *__modes) __attribute__ ((__nothrow__ , __leaf__)) ;
455 # 319 "/usr/include/stdio.h" 3 4
456 extern FILE *fmemopen (void *__s, size_t __len, const char *__modes)
457   __attribute__ ((__nothrow__ , __leaf__)) ;
458 
459 
460 
461 
462 extern FILE *open_memstream (char **__bufloc, size_t *__sizeloc) __attribute__ ((__nothrow__ , __leaf__)) ;
463 
464 
465 
466 
467 
468 
469 extern void setbuf (FILE *__restrict __stream, char *__restrict __buf) __attribute__ ((__nothrow__ , __leaf__));
470 
471 
472 
473 extern int setvbuf (FILE *__restrict __stream, char *__restrict __buf,
474       int __modes, size_t __n) __attribute__ ((__nothrow__ , __leaf__));
475 
476 
477 
478 
479 
480 extern void setbuffer (FILE *__restrict __stream, char *__restrict __buf,
481          size_t __size) __attribute__ ((__nothrow__ , __leaf__));
482 
483 
484 extern void setlinebuf (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__));
485 
486 
487 
488 
489 
490 
491 
492 
493 extern int fprintf (FILE *__restrict __stream,
494       const char *__restrict __format, ...);
495 
496 
497 
498 
499 extern int printf (const char *__restrict __format, ...);
500 
501 extern int sprintf (char *__restrict __s,
502       const char *__restrict __format, ...) __attribute__ ((__nothrow__));
503 
504 
505 
506 
507 
508 extern int vfprintf (FILE *__restrict __s, const char *__restrict __format,
509        __gnuc_va_list __arg);
510 
511 
512 
513 
514 extern int vprintf (const char *__restrict __format, __gnuc_va_list __arg);
515 
516 extern int vsprintf (char *__restrict __s, const char *__restrict __format,
517        __gnuc_va_list __arg) __attribute__ ((__nothrow__));
518 
519 
520 
521 
522 
523 extern int snprintf (char *__restrict __s, size_t __maxlen,
524        const char *__restrict __format, ...)
525      __attribute__ ((__nothrow__)) __attribute__ ((__format__ (__printf__, 3, 4)));
526 
527 extern int vsnprintf (char *__restrict __s, size_t __maxlen,
528         const char *__restrict __format, __gnuc_va_list __arg)
529      __attribute__ ((__nothrow__)) __attribute__ ((__format__ (__printf__, 3, 0)));
530 
531 # 412 "/usr/include/stdio.h" 3 4
532 extern int vdprintf (int __fd, const char *__restrict __fmt,
533        __gnuc_va_list __arg)
534      __attribute__ ((__format__ (__printf__, 2, 0)));
535 extern int dprintf (int __fd, const char *__restrict __fmt, ...)
536      __attribute__ ((__format__ (__printf__, 2, 3)));
537 
538 
539 
540 
541 
542 
543 
544 
545 extern int fscanf (FILE *__restrict __stream,
546      const char *__restrict __format, ...) ;
547 
548 
549 
550 
551 extern int scanf (const char *__restrict __format, ...) ;
552 
553 extern int sscanf (const char *__restrict __s,
554      const char *__restrict __format, ...) __attribute__ ((__nothrow__ , __leaf__));
555 # 443 "/usr/include/stdio.h" 3 4
556 extern int fscanf (FILE *__restrict __stream, const char *__restrict __format, ...) __asm__ ("" "__isoc99_fscanf")
557 
558                                ;
559 extern int scanf (const char *__restrict __format, ...) __asm__ ("" "__isoc99_scanf")
560                               ;
561 extern int sscanf (const char *__restrict __s, const char *__restrict __format, ...) __asm__ ("" "__isoc99_sscanf") __attribute__ ((__nothrow__ , __leaf__))
562 
563                       ;
564 # 463 "/usr/include/stdio.h" 3 4
565 
566 
567 
568 
569 
570 
571 
572 
573 extern int vfscanf (FILE *__restrict __s, const char *__restrict __format,
574       __gnuc_va_list __arg)
575      __attribute__ ((__format__ (__scanf__, 2, 0))) ;
576 
577 
578 
579 
580 
581 extern int vscanf (const char *__restrict __format, __gnuc_va_list __arg)
582      __attribute__ ((__format__ (__scanf__, 1, 0))) ;
583 
584 
585 extern int vsscanf (const char *__restrict __s,
586       const char *__restrict __format, __gnuc_va_list __arg)
587      __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__format__ (__scanf__, 2, 0)));
588 # 494 "/usr/include/stdio.h" 3 4
589 extern int vfscanf (FILE *__restrict __s, const char *__restrict __format, __gnuc_va_list __arg) __asm__ ("" "__isoc99_vfscanf")
590 
591 
592 
593      __attribute__ ((__format__ (__scanf__, 2, 0))) ;
594 extern int vscanf (const char *__restrict __format, __gnuc_va_list __arg) __asm__ ("" "__isoc99_vscanf")
595 
596      __attribute__ ((__format__ (__scanf__, 1, 0))) ;
597 extern int vsscanf (const char *__restrict __s, const char *__restrict __format, __gnuc_va_list __arg) __asm__ ("" "__isoc99_vsscanf") __attribute__ ((__nothrow__ , __leaf__))
598 
599 
600 
601      __attribute__ ((__format__ (__scanf__, 2, 0)));
602 # 522 "/usr/include/stdio.h" 3 4
603 
604 
605 
606 
607 
608 
609 
610 
611 
612 extern int fgetc (FILE *__stream);
613 extern int getc (FILE *__stream);
614 
615 
616 
617 
618 
619 extern int getchar (void);
620 
621 # 550 "/usr/include/stdio.h" 3 4
622 extern int getc_unlocked (FILE *__stream);
623 extern int getchar_unlocked (void);
624 # 561 "/usr/include/stdio.h" 3 4
625 extern int fgetc_unlocked (FILE *__stream);
626 
627 
628 
629 
630 
631 
632 
633 
634 
635 
636 
637 extern int fputc (int __c, FILE *__stream);
638 extern int putc (int __c, FILE *__stream);
639 
640 
641 
642 
643 
644 extern int putchar (int __c);
645 
646 # 594 "/usr/include/stdio.h" 3 4
647 extern int fputc_unlocked (int __c, FILE *__stream);
648 
649 
650 
651 
652 
653 
654 
655 extern int putc_unlocked (int __c, FILE *__stream);
656 extern int putchar_unlocked (int __c);
657 
658 
659 
660 
661 
662 
663 extern int getw (FILE *__stream);
664 
665 
666 extern int putw (int __w, FILE *__stream);
667 
668 
669 
670 
671 
672 
673 
674 
675 extern char *fgets (char *__restrict __s, int __n, FILE *__restrict __stream)
676      ;
677 # 638 "/usr/include/stdio.h" 3 4
678 extern char *gets (char *__s) __attribute__ ((__deprecated__));
679 
680 
681 # 665 "/usr/include/stdio.h" 3 4
682 extern __ssize_t __getdelim (char **__restrict __lineptr,
683           size_t *__restrict __n, int __delimiter,
684           FILE *__restrict __stream) ;
685 extern __ssize_t getdelim (char **__restrict __lineptr,
686         size_t *__restrict __n, int __delimiter,
687         FILE *__restrict __stream) ;
688 
689 
690 
691 
692 
693 
694 
695 extern __ssize_t getline (char **__restrict __lineptr,
696        size_t *__restrict __n,
697        FILE *__restrict __stream) ;
698 
699 
700 
701 
702 
703 
704 
705 
706 extern int fputs (const char *__restrict __s, FILE *__restrict __stream);
707 
708 
709 
710 
711 
712 extern int puts (const char *__s);
713 
714 
715 
716 
717 
718 
719 extern int ungetc (int __c, FILE *__stream);
720 
721 
722 
723 
724 
725 
726 extern size_t fread (void *__restrict __ptr, size_t __size,
727        size_t __n, FILE *__restrict __stream) ;
728 
729 
730 
731 
732 extern size_t fwrite (const void *__restrict __ptr, size_t __size,
733         size_t __n, FILE *__restrict __s);
734 
735 # 737 "/usr/include/stdio.h" 3 4
736 extern size_t fread_unlocked (void *__restrict __ptr, size_t __size,
737          size_t __n, FILE *__restrict __stream) ;
738 extern size_t fwrite_unlocked (const void *__restrict __ptr, size_t __size,
739           size_t __n, FILE *__restrict __stream);
740 
741 
742 
743 
744 
745 
746 
747 
748 extern int fseek (FILE *__stream, long int __off, int __whence);
749 
750 
751 
752 
753 extern long int ftell (FILE *__stream) ;
754 
755 
756 
757 
758 extern void rewind (FILE *__stream);
759 
760 # 773 "/usr/include/stdio.h" 3 4
761 extern int fseeko (FILE *__stream, __off_t __off, int __whence);
762 
763 
764 
765 
766 extern __off_t ftello (FILE *__stream) ;
767 # 792 "/usr/include/stdio.h" 3 4
768 
769 
770 
771 
772 
773 
774 extern int fgetpos (FILE *__restrict __stream, fpos_t *__restrict __pos);
775 
776 
777 
778 
779 extern int fsetpos (FILE *__stream, const fpos_t *__pos);
780 # 815 "/usr/include/stdio.h" 3 4
781 
782 # 824 "/usr/include/stdio.h" 3 4
783 
784 
785 extern void clearerr (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__));
786 
787 extern int feof (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ;
788 
789 extern int ferror (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ;
790 
791 
792 
793 
794 extern void clearerr_unlocked (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__));
795 extern int feof_unlocked (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ;
796 extern int ferror_unlocked (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ;
797 
798 
799 
800 
801 
802 
803 
804 
805 extern void perror (const char *__s);
806 
807 
808 
809 
810 
811 
812 # 1 "/usr/include/i386-linux-gnu/bits/sys_errlist.h" 1 3 4
813 # 26 "/usr/include/i386-linux-gnu/bits/sys_errlist.h" 3 4
814 extern int sys_nerr;
815 extern const char *const sys_errlist[];
816 # 854 "/usr/include/stdio.h" 2 3 4
817 
818 
819 
820 
821 extern int fileno (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ;
822 
823 
824 
825 
826 extern int fileno_unlocked (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ;
827 # 873 "/usr/include/stdio.h" 3 4
828 extern FILE *popen (const char *__command, const char *__modes) ;
829 
830 
831 
832 
833 
834 extern int pclose (FILE *__stream);
835 
836 
837 
838 
839 
840 extern char *ctermid (char *__s) __attribute__ ((__nothrow__ , __leaf__));
841 # 913 "/usr/include/stdio.h" 3 4
842 extern void flockfile (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__));
843 
844 
845 
846 extern int ftrylockfile (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ;
847 
848 
849 extern void funlockfile (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__));
850 # 943 "/usr/include/stdio.h" 3 4
851 
852 # 9 "hello.c" 2
853 
854 int main(int argc, char* argv[])
855 {
856     printf("Hello , world !\n");
857 
858     return 0;
859 }
hello.i
 1     .file    "hello.c"
 2     .section    .rodata
 3 .LC0:
 4     .string    "Hello , world !"
 5     .text
 6     .globl    main
 7     .type    main, @function
 8 main:
 9 .LFB0:
10     .cfi_startproc
11     pushl    %ebp
12     .cfi_def_cfa_offset 8
13     .cfi_offset 5, -8
14     movl    %esp, %ebp
15     .cfi_def_cfa_register 5
16     andl    $-16, %esp
17     subl    $16, %esp
18     movl    $.LC0, (%esp)
19     call    puts
20     movl    $0, %eax
21     leave
22     .cfi_restore 5
23     .cfi_def_cfa 4, 4
24     ret
25     .cfi_endproc
26 .LFE0:
27     .size    main, .-main
28     .ident    "GCC: (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4"
29     .section    .note.GNU-stack,"",@progbits
hello.s

     gcc编译过程:http://lib.csdn.net/article/c/66184

  1.去掉程序中的注释;

  2.文件包含:当对C源程序进行预处理时,文件包含指的是将.c文件包含的头文件内容复制到当前.c文件中。

    1》、第一种:#include <stdio.h>  直接去系统头文件目录下寻找所包含的头文件。

    2》、第二种:#include "head.h"   先在当前目录下寻找所包含的头文件,如果找不到,则再去系统头文件目录下寻找所包含的头文件。

  3.宏替换

    当对C源程序进行预处理时,如果程序中有事先定义好的宏,则会将所有的宏后面的字符串替换,例如:

     

    1》预定义宏:   

1 __FILE__       //正在编译的文件名(字符串常量)  
2 __LINE__       //文件当前的行号(整型常量)
3 __FUNCTION__    //当前所在的函数名(字符串常量)
4 __DATE__      //预编译文件的日期(字符串常量)
5 __TIME__      //预编译文件的时间(字符串常量)
6 __STDC__      //判断编译器是否遵循ANSI C,是则为1(整型常量)
Predefine Macros

      

     2》不带参数的宏:#define   宏名  字符串

 1 /*******************************************************************
 2  *   > File Name: noParamMacros.c
 3  *   > Author: fly
 4  *   > Mail: XXXXXXXX@icode.com
 5  *   > Create Time: Sun 17 Sep 2017 01:00:07 PM CST
 6  ******************************************************************/
 7 
 8 #include <stdio.h>
 9 
10 #define PI  3.14*2
11 #define M   60
12 #define S   "HelloWorld"
13 
14 int main(int argc, char* argv[])
15 {
16     printf("%f\n", PI);
17     printf("%d\n", M);
18     printf("%s\n", S);
19 
20     return 0;
21 }
noParamMacros.c

     3》带参数的宏:可以像函数一样被调用。

 1 /*******************************************************************
 2  *   > File Name: paramMacros.c
 3  *   > Author: fly
 4  *   > Mail: XXXXXXXX@icode.com
 5  *   > Create Time: Sun 17 Sep 2017 01:40:15 PM CST
 6  ******************************************************************/
 7 
 8 #include <stdio.h>
 9 
10 #define FUN(a, b)   a+b*a
11 
12 #define     FALSE   0
13 #define     TRUE    1
14 
15 int fun(int a, int b){
16     return a+b*a;
17 }
18 
19 int main(int argc, char* argv[])
20 {
21     int a = 5, b =3;
22     int c;
23 
24     c = fun(a, b);  //函数调用
25     printf("c = %d\n", c);
26 
27     c = FUN(a, b);  //宏调用
28 
29     float f;
30 
31 #if (DataType == FALSE)
32     f = fun(3.1, 4.5);  //Data type is error
33     printf("f = %f\n", f);
34 #else
35     f = FUN(3.1, 4.5);  //Data type is correct
36     printf("f = %f\n", f);
37 #endif
38 
39     return 0;
40 }
paramMacros.c

      在上述例子中,由于传参时,可能会传一个表达式,这是调用带参宏就会导致结果不正确,所以一般在定义带参宏时,都会如下去定义:  #define  FUN(a, b)  (a)+(b)*(a)

  4.条件编译:在编译程序之前,按照某个条件来选择需要编译哪一段代码。

    1》第一种方式:

    

 

 1 /*******************************************************************
 2  *   > File Name: ifdef.c
 3  *   > Author: fly
 4  *   > Mail: XXXXXXXX@icode.com
 5  *   > Create Time: Sun 17 Sep 2017 02:51:43 PM CST
 6  ******************************************************************/
 7 
 8 #include <stdio.h>
 9 
10 #define     DEBUG
11 
12 //有如下两个函数,如果要测试这两个函数是否正确,则必须写主函数测试
13 void fun1(void){
14     printf("hello world\n");
15 }
16 
17 void fun2(void){
18     printf("This is a good idea !\n");
19 }
20 
21 //下面为测试代码
22 #ifdef  DEBUG
23 int main(int argc, char* argv[])
24 {
25     fun1();
26     fun2();
27 
28     return 0;
29 }
30 #endif
ifdef.c

 

    2》第二种方式:

    

 

 1 #ifdef __HEAD_H_
 2 #define __HEAD_H_
 3 
 4 #include <stdio.h>
 5 
 6 int x = 100;
 7 
 8 #endif
 9 
10 //该条件编译的作用是,防止头文件被多次(重复)包含。
ifndef

    3》第三种方式:

    

 1 //用于注释一段代码
 2 #if (0)
 3 #include "head.h"
 4 #include "head.h"
 5 #include "head.h"
 6 #include "head.h"
 7 #include "head.h"
 8 #include "head.h"
 9 #include "head.h"
10 #include "head.h"
11 #endif
if.c

 

二、字节序 

  1.计算机在存储多字节数据时,数据内部各个字节的存储顺序称为字节序;

 

      4字节:unsigned int word = 0x12345678;

        

  2.端序

    1》小端序(little-endian):最高有效位所在的字节放在最高字节位置,其他字节依次放在低字节位置,则该字节序称为高位优先。

    2》大端序(big-endian):最低有效位所在的字节放在最高字节位置,其他字节依次放在低字节位置,则该字节序称为低位优先。

 1 /*******************************************************************
 2  *   > File Name: endian.c
 3  *   > Author: fly
 4  *   > Mail: XXXXXXXX@icode.com
 5  *   > Create Time: Sun 17 Sep 2017 04:34:11 PM CST
 6  ******************************************************************/
 7 
 8 #include <stdio.h>
 9 #include <stdbool.h>
10 
11 #define FALSE   0
12 #define TRUE    1
13 
14 bool is_little_endian(void){
15     bool ret;
16     unsigned int word = 0x12345678;
17 
18     unsigned char byte0 = *((unsigned char *)&word + 0);
19     unsigned char byte1 = *((unsigned char *)&word + 1);
20     unsigned char byte2 = *((unsigned char *)&word + 2);
21     unsigned char byte3 = *((unsigned char *)&word + 3);
22 
23     printf("%p---->0x%hhx\n", &byte0, byte0);
24     printf("%p---->0x%hhx\n", &byte1, byte1);
25     printf("%p---->0x%hhx\n", &byte2, byte2);
26     printf("%p---->0x%hhx\n", &byte3, byte3);
27 
28     if(byte0 == 0x78){
29         printf("the machine is little endian !\n");
30         ret = TRUE;
31     }else if(byte0 == 0x12){
32         printf("the machine is big endian !\n");
33         ret = FALSE;
34     }
35 
36     return ret;
37 }
38 
39 int main(int argc, char* argv[])
40 {
41     if(is_little_endian() == TRUE){
42         printf("Little endian is true !\n");
43     }
44 
45     return 0;
46 }
View Code

     执行结果: 

 1 /*******************************************************************
 2  *   > File Name: endian1.c
 3  *   > Author: fly
 4  *   > Mail: XXXXXXXX@icode.com
 5  *   > Create Time: Sun 17 Sep 2017 05:02:58 PM CST
 6  ******************************************************************/
 7 
 8 #include <stdio.h>
 9 
10 union A{
11     unsigned int word;
12     unsigned char byte;
13 };
14 
15 int main(int argc, char* argv[])
16 {
17     union A un;
18 
19     un.word = 0x12345678;
20     if(un.byte == 0x78){
21         printf("the machine is little endian !\n");
22     }else if(un.byte == 0x12){
23         printf("the machine is big endian !\n");
24     }
25 
26     return 0;
27 }
使用结构体判断大小端序

 

三、地址对齐

  为了提高CPU从内存中存取数据的效率,在给数据分配内存空间时,会有意的将数据放在某些地址位置,这种分配空间的方式称为地址对齐。  

  1》自然对齐:在给数据分配空间是时,如果数据的起始地址能够被数据的长度整除,则该分配空间的方式为自然对齐。

  2》数据的M值:

    对于每一个数据都有M值,M值如下:

      1)对于基本数据类型:

        如果该数据的长度小于机器字字长,则它的M值为自身的长度;

        如果该数据的长度大于或者等于机器字长,则它的M值为机器字长;

      2)对于数组:

        M值为元素的M值;

      3)对于结构体,共用体:

        M值为成员中最大的M值;

  3》适当对齐:在给数据分配空间时,如果数据的起始地址能够被数据的M值整除,则该分配空间的方式为适当对齐。

  4》结构体的存储:

 

 1 /*******************************************************************
 2  *   > File Name: align.c
 3  *   > Author: fly
 4  *   > Mail: XXXXXXXX@icode.com
 5  *   > Create Time: Sun 17 Sep 2017 05:15:23 PM CST
 6  ******************************************************************/
 7 
 8 #include <stdio.h>
 9 
10 struct param{
11     char a;
12     short b;
13     int c;
14 };
15 
16 struct param1{
17     char a;
18     int b;
19     short c;
20 };
21 
22 int main(int argc, char* argv[])
23 {
24     struct param p1;
25     printf("sizeof(struct param) = %d\tsizeof p1 = %d\n", sizeof(struct param), sizeof p1);
26 
27     struct param1 p2;
28     printf("sizeof(struct param1) = %d\tsizeof p2 = %d\n", sizeof(struct param1), sizeof p2);
29 
30     return 0;
31 }
structAlign.c

 

   执行结果:

 

转载于:https://www.cnblogs.com/feige1314/p/7535537.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值