473,473 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how do compiler differentiate strings and intigers?

2 New Member
i was programming an assembler as part of my assignment. In that to check errors in the program, i wanted to check whether the argument is an intiger or a character? Can any one help me how to do that?
Thanks in advance
Jan 11 '07 #1
3 1675
horace1
1,510 Recognized Expert Top Contributor
i was programming an assembler as part of my assignment. In that to check errors in the program, i wanted to check whether the argument is an intiger or a character? Can any one help me how to do that?
Thanks in advance
this is not simple as once a character has been read into memory it is represented by an integer character code such as ASCII, see
http://www.asciitable.com/

you can check if an integer represents a character code such as a digit, alphabetic, etc using functions such as isdigit(), isalpha(), see
http://www.cppreference.com/stdstring/index.html

however, although decimal 65 is the ASCII code for A it could have been entered as an integer
Jan 11 '07 #2
DeMan
1,806 Top Contributor
a byte is a byte is a byte is a byte.....

(Incedently a character is 1 byte (2^8 or 0 - 255 ) and an integer is 2 bytes (2 ^16 or 0 - 65536 ) but that does't help because you can't necessarily tell the difference between 1 integer or 2 characters).

Compilers are very trusting beasts. They store all the variables you declare in a look-up table. When they come accross a variable, they look it up in the table and check that it's type is the same as what you said before (this is about where you start getting warnings (sometimes errors, but usually warnings I think)that there are problems with types).

Assuming someone has defined a var to be something beforehand, I would reccommend you do something similar, store the variables, their types (and possibly value) in a table and make sure their type is never changed.



Slightly (a lot perhaps) off topic (as always): This is why casting can be a bad idea unless you know for a fact you want to. The cast get's rid of the warning/error because the compiler says "This doesn't look right...wait a minute, there's an explicit cast so this is derliberate...I'll assume this chap knows what he's doing". You should always be very careful in casts, because even though the compiler can see what you are doing is strange, by adding a cast you are assuring it that you definitely intend to use that value as a different type.
Jan 11 '07 #3
Ganon11
3,652 Recognized Expert Specialist
Incedently a character is 1 byte (2^8 or 0 - 255 ) and an integer is 2 bytes (2 ^16 or 0 - 65536)
Strictly speaking, an integer's byte value varies from system to system. Your 2 byte integer is specifically known as a short int, whereas there can be a 4 byte integer (0 to 4,294,967,296 (unsigned)) known as a long int. Using just int will use your system default - for mine, it is the long int.

But a char is always 1 byte.
Jan 11 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

29
by: Daniel Rudy | last post by:
Hello, Consider the following code fragment: fileptr = fopen(param->filename, "r"); if (fileptr == NULL) { error("digest.c: digest_file: Open File ", errno); return(-2); }
4
by: emmba | last post by:
Hello. If anyone could help me, I would be very grateful. My program will compile, but when I run it, the function stringOperation is not returning the correct value. The premise of my...
3
by: Sachin | last post by:
Hi Folks, I have one query in regarding const varible interpretaion by C/C++ compiler. How Compiler actually differentiate between normal stack varible and const varible during program execution?...
0
by: Alejandro Gaio | last post by:
Hello All, I have a problem that appeared with the NEW VERSION of the vb.net compiler (VS 2008). To resume things, I have a project (call it "DocumentAdministrator") with several forms, and two...
0
by: Terry Reedy | last post by:
Orestis Markou wrote: The lockstep stuff is either new stuff which does not (at least, is intended not to) affect old code, or changes that you have to request via __future__ imports. Much 1.5...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.