473,796 Members | 2,729 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Difference between '\0' and 0

Hello all,

If c is a char then is there any difference between

c = '\0'

and

c = 0

?
Regards,
August
Nov 14 '05
39 4483
Emmanuel Delahaye wrote:
Robert Gamble wrote on 29/05/05 :
(The literal 0 can also denote the nil pointer)

A nil pointer? Perhaps you mean NULL pointer constant, but this would
not apply to type char which is being discussed here...

'nil pointer' is a generic term used in Computer Science. Its
C-implementation is null pointer constant or NULL.


Thanks for the backup, this is exactly what I was trying to say.

-- August
Nov 14 '05 #21
Robert Gamble wrote:
August Karlstrom wrote:
Robert Gamble wrote:
August Karlstrom wrote:
> (The literal 0 can also denote the nil pointer)

A nil pointer? Perhaps you mean NULL pointer constant, but this would
not apply to type char which is being discussed here...
I used "nil pointer" to emphasize the distinction between the "points to
nothing" concept and the C macro constant NULL.


You said that literal 0 can denote the "nil pointer". There is no nil
pointer in C, but there is a NULL pointer constant


There are null pointer constants which become null pointers when
converted to a pointer. NULL is an implementation defined null pointer
constant available when you include certain headers.
which can be expressed as a literal 0 in a pointer context.


Any integer constant with zero value is a null pointer constant, by
definition.

People, there's a whole section of the FAQ devoted to this! ;)

--
Peter

Nov 14 '05 #22
Keith Thompson wrote:
C uses some specific pointer representation to represent a null
pointer.


Note: there may be more than one representation for null pointers.

--
Peter

Nov 14 '05 #23
Emmanuel Delahaye wrote:
August Karlstrom wrote on 29/05/05 :
If c is a char then is there any difference between
c = '\0'
and
c = 0
The Lint program Splint thinks there is a difference:
int main(void)
{
char c;

c = '\0';
c = 0;
return 0;
}
$ splint test.c
Splint 3.1.1 --- 15 Jun 2004

test.c: (in function main)
test.c:6:4: Assignment of int to char: c = 0
Types are incompatible. (Use -type to inhibit warning)

Finished checking --- 1 code warning

It's true that and int is not a char. Why in the world are you using a
char ? The cases where a single char is necessary are extremely rare
(only scanf("%c", &c) comes to my mind, and scanf() is not a recommended
function...)


You're right, this issue is more of theoretical interest.
That said, Lint seems to consider that '\0' is a char that is wrong in
C. (Or maybe, Lint is checking in C++ mode, in that case 0 is an int and
'\0' is a char). Your extension seems to be .c, that is correct for a
C-program. Check the Lint configuration.


Splint is a C only checker.

-- August
Nov 14 '05 #24
Emmanuel Delahaye wrote:
Dik T. Winter wrote on 29/05/05 :
<...> The conclusion is that Splint does not handle character
constants correctly.


Arf! Who has checked the checker ?


You are missing the point. Splint doesn't have to handle character
constants correctly, or anything else for that matter. It is NOT a
compiler. It is a tool, whose purpose is to point out questionable
or problematic constructs. Further action is up to the programmer
and his compiler.

A better comparison is a spell checker, which probably will
highlight things that smell suspiciously like a mis-spelling. It
isn't expected to be right all the time.

--
Some informative links:
news:news.annou nce.newusers
http://www.geocities.com/nnqweb/
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.caliburn.nl/topposting.html
http://www.netmeister.org/news/learn2quote.html
Nov 14 '05 #25
On Sun, 29 May 2005 20:37:21 GMT, Keith Thompson
<ks***@mib.or g> wrote:
A digression: In my opinion, C depends too heavily on implicit
conversions. If I were designing the language from scratch, most
conversions that are implicit in C would probably be explicit -- but
most of them would be expressed by some mechanism less heavyweight
than a cast. The resulting code would probably be more verbose than
typical C. If you like extreme terseness, be glad that I don't
actually design programming languages.
I would have no problem with you designing such a language, since that
language would not be C and so I wouldn't be using it <g>.
But given the actual design of
C, it almost always makes sense to use implicit conversions rather
than explicit casts, which tend to swat flies with sledgehammers.
Implicit conversions are bad from a language design point of view, but
good (or at least far better than the alternative) from a C
programming point of view.


If I want a strongly typed language I know where to find Ada <g>...

Chris C
Nov 14 '05 #26
Chris Croughton wrote:
On Sun, 29 May 2005 20:37:21 GMT, Keith Thompson
<ks***@mib.or g> wrote:

A digression: In my opinion, C depends too heavily on implicit
conversions . If I were designing the language from scratch, most
conversions that are implicit in C would probably be explicit -- but
most of them would be expressed by some mechanism less heavyweight
than a cast. The resulting code would probably be more verbose than
typical C. If you like extreme terseness, be glad that I don't
actually design programming languages.

I would have no problem with you designing such a language, since that
language would not be C and so I wouldn't be using it <g>.

But given the actual design of
C, it almost always makes sense to use implicit conversions rather
than explicit casts, which tend to swat flies with sledgehammers.
Implicit conversions are bad from a language design point of view, but
good (or at least far better than the alternative) from a C
programming point of view.

If I want a strongly typed language I know where to find Ada <g>...


Or why not Oberon-2.

-- August
Nov 14 '05 #27
Dik T. Winter wrote:

'\377' is an int with value 255


Is that correct? I know that '\xFF' is implementation-defined
as to whether it is -1 or 255 ..

Nov 14 '05 #28
Old Wolf wrote:
Dik T. Winter wrote:
'\377' is an int with value 255
Is that correct?


In strict terms, no.
I know that '\xFF' is implementation-defined
as to whether it is -1 or 255 ..


The value is the value c would have if it were evaluated as
in...

unsigned char x = 255;
int c = * (char *) &x;

In other words, the byte value of the constant is interpreted
as a (plain) char, and subsequently converted to an int.

It is implementation defined whether plain char is signed or
unsigned.

On implementations where CHAR_BIT > 8, and on implementations
where plain char is unsigned, the value is 255.

On 8-bit, signed plain char, ones complement or signed
magnitude machines, the value is effectively unspecified
under C90. C99 limits the representation of negative
integers more thoroughly, so the value is either -1, -0 or
-127 for 2c, 1c and sm representations respectively.

It is the view of many clc regulars that 1c and sm machines
must have unsigned plain char, if the implementation is
to have any QoI. However, there is nothing the standard
which precludes low QoI implementations .

--
Peter

Nov 14 '05 #29
On Mon, 30 May 2005 20:51:41 GMT, August Karlstrom
<fu********@com hem.se> wrote:
Chris Croughton wrote:

If I want a strongly typed language I know where to find Ada <g>...


Or why not Oberon-2.


Not powerful enough. For instance, one of the features I like in Ada is
declaring variables with specific ranges (-3..7 etc.), so that they
can't go out of bound without throwing an exception. Oberon-2 was, I
gather, created as a language for teaching, like Pascal (but later so it
learnt from some of the pitfalls of early Pascal), Ada was designed for
Real World(tm) tasks.

(That's not a criticism of Oberon-2, which is fine for its purpose, it's
just not as good for my purposes...)

Chris C
Nov 14 '05 #30

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

34
7114
by: yensao | last post by:
Hi, I have a hard time to understand difference and similarities between Relational database model and the Object-Oriented model. Can somebody help me with this? Thank you in advance. Yensao
21
3023
by: b83503104 | last post by:
Hi, Can someone tell me the difference between single quote and double quote? Thanks
26
4422
by: Frank | last post by:
For my website i would like to display the age of my son in years, months, days and hours. For now i manage to get a result for totals. Like the total number of days. This is the beginning: starttime = Date.parse("Aug 10,2003, 07:07") sdt = new Date(starttime)
21
2853
by: Rich | last post by:
I was considering C# for developing a scientific application, but I have noticed a ~30% difference between VC++ .NET and C# on the same machine, under identical conditions: double a = 0,b = 0, c = 0, d = 0, e = 0; for(int n = 0; n != 6000000; n++) { a = n % 5 *2 / 3 - 4 + 6 / 3 - n + n * 2; b = n * 2.3 - 1 *2 / 3 - 4 + 6 / 3 - n + n * 2; c = n * 3 / 3.5 *2 / 3 - 4 + 6 / 3 - n + n * 2;
4
15759
by: jamesyreid | last post by:
Hi, I'm really sorry to post this as I know it must have been asked countless times before, but I can't find an answer anywhere. Does anyone have a snippet of JavaScript code I could borrow which calculated the difference in years and days between two dates, and takes leap years into account? I'm calculating the difference in the usual way, i.e....
3
4163
by: bbawa1 | last post by:
Hi, I have a table which has a field ItemsReceived of type datetime. I have a grid view which has two columns. In first column i have to show the data from field ItemsReceived and in second column I have to show difference between Currenttime and date from ItemReceived. How can I do that.
12
2717
by: Petronius | last post by:
Hallo, does anyone have an idea how to implement difference lists in Javascript? Thanks allot in advance
5
3490
by: Julius | last post by:
Hej dudes, I need to calc the difference between two timestamps / dates ... For example what i need to calculate: Date 1: 2007.11.06 - 20:13:04 Date 2: 2007.11.07 - 21:13:04 Difference: 1 day, 1hour
9
2682
by: viki1967 | last post by:
Hi all! This new forum its great! :) Congratulations !!! My answer: why this my code not working? Nothing error but not work the difference.... : <html>
11
12127
by: cmb3587 | last post by:
I have two arrays and I'm trying to create a 3rd array that is the difference between the two arrays Ex: arrayA: 3 5 8 9 arrayB: 3 4 6 9 difference of A-B: 5 8 however, my code is just returning me an array of 0's
0
10465
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10242
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10200
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9061
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6800
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5453
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4127
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2931
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.