Re: Code Comprehension
- From: Pascal Bourguignon <pjb@xxxxxxxxxxxxxxxxx>
- Date: Sun, 27 Aug 2006 02:19:45 +0200
ena8t8si@xxxxxxxxx writes:
The type of 0 and the type of '\0' are both int. There
is no difference between them in types of type or value.
The type of 0, '\0', "0", struct{char a[]="zero";} are both integer too.
Don't believe me?
[pjb@thalassa tmp]$ cat e.c
int main(void){
int i=0;
char c='\0';
char* s="0";
struct {char a[10];} t={"zero"};
i+=1;
return(i);}
[pjb@thalassa tmp]$ gcc -g -o e e.c
[pjb@thalassa tmp]$ gdb e
GNU gdb 5.3
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i586-suse-linux"...
(gdb) break main
Breakpoint 1 at 0x8048325: file e.c, line 2.
(gdb) run
Starting program: /tmp/e
Breakpoint 1, main () at e.c:2
2 int i=0;
(gdb) step
3 char c='\0';
(gdb)
4 char* s="0";
(gdb)
5 struct {char a[10];} t={"zero"};
(gdb)
6 i+=1;
(gdb)
7 return(i);}
(gdb) x/x &i
0xbff02dec: 0x00000001 ; an integer
(gdb) x/x &c
0xbff02deb: 0x00000100 ; another integer
(gdb) x/x &s
0xbff02de4: 0x08048434 ; still an integer
(gdb) x/x &t
0xbff02dd0: 0x6f72657a ; alway an integer
(gdb) quit
A debugging session is active.
Do you still want to close the debugger?(y or n) y
So don't be silly, don't program in assembler in C, even if it's
possible. You're not implementing another device driver or another
low-level kernel function! Write:
enum{false,true};
typedef char bool;
typedef signed char int8;
typedef unsigned char CHAR;
bool b=false; if(b){...}
uint8 i=0; if(i!=0){...}
CHAR c='\0'; if(c!='\0'){...}
random_type* p=NULL; if(p!=NULL){...}
--
__Pascal Bourguignon__ http://www.informatimago.com/
This universe shipped by weight, not volume. Some expansion may have
occurred during shipment.
.
- Follow-Ups:
- Re: Code Comprehension
- From: Phlip
- Re: Code Comprehension
- References:
- Code Comprehension
- From: jj
- Re: Code Comprehension
- From: Pascal Bourguignon
- Re: Code Comprehension
- From: Logan Shaw
- Re: Code Comprehension
- From: Pascal Bourguignon
- Re: Code Comprehension
- From: Logan Shaw
- Re: Code Comprehension
- From: Rob Thorpe
- Code Comprehension
- Prev by Date: Re: Code Comprehension
- Next by Date: Re: VB6.0 and Constructors
- Previous by thread: Re: Code Comprehension
- Next by thread: Re: Code Comprehension
- Index(es):
Relevant Pages
|