LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Closed Thread
  Search this Thread
Old 06-14-2010, 06:13 AM   #1
elizas
LQ Newbie
 
Registered: Jun 2010
Posts: 2

Rep: Reputation: 0
Data Type in Programming


I declared a variable as int data type which was a placeholder for a result status (meaning, based on the result status that variable varies from 0/1/2/3. It can contain only these four values).

“int” data type is 4 byte integer in C#. But I can declare this variable as “sbyte” which represents a 1 byte integer. Since that variable contains only 1 or 2 or 3 or 4, declaring the variable as “int” is wastage of memory space.

Before declaring any variable we need to just think of the memory space needed for that variable, our requirement, any other good alternative for this variable.

<<mod edit: delete advertising link>>

Last edited by pixellany; 06-14-2010 at 06:18 AM.
 
Old 06-14-2010, 06:19 AM   #2
dracuss
Member
 
Registered: May 2006
Location: Chisinau, Moldova
Distribution: Gentoo, Debian sid
Posts: 151

Rep: Reputation: 29
elizas, I'm not a very experimented programmer, but I would suggest using the enum type. In C it's not very different from int, but as much as I know it will ease your life a bit.
 
Old 06-14-2010, 06:19 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Elizas;
If you want to advertise here, please see the links at the bottom of the page.
 
Old 06-14-2010, 06:31 AM   #4
elizas
LQ Newbie
 
Registered: Jun 2010
Posts: 2

Original Poster
Rep: Reputation: 0
Data Type in Programming

I declared a variable as “int” data type for a PatientId. It worked fine in local, but when that code went to LIVE, the application gave exception because in LIVE PatientId is too long to accommodate in int data type.

So before declaring any variable we need to consider all the situations, application scope, environment .Even one code may be working fine today, after 1/ 10/20 days/months/years it will fail due to just due to data type declaration mistake.

Think more; write less is the policy for better programming.

My Experience No 2:

I declared a variable as int data type which was a placeholder for a result status (meaning, based on the result status that variable varies from 0/1/2/3. It can contain only these four values).

“int” data type is 4 byte integer in C#. But I can declare this variable as “sbyte” which represents a 1 byte integer. Since that variable contains only 1 or 2 or 3 or 4, declaring the variable as “int” is wastage of memory space.

Before declaring any variable we need to just think of the memory space needed for that variable, our requirement, any other good alternative for this variable.

<<mod edit: deleted advertising link>>

Last edited by pixellany; 06-14-2010 at 06:34 AM.
 
Old 06-14-2010, 06:36 AM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Second warning: Do not include the advertising link in any future posts

Last edited by pixellany; 06-14-2010 at 07:03 AM.
 
Old 06-14-2010, 07:32 AM   #6
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721
Why didn't the OP mention C# in the title?

And why isn't this in the Programming forum?
 
Old 06-14-2010, 09:13 PM   #7
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
1. probably because the posts were motivated by advertising (now removed)

2. because it may just get closed or deleted
 
  


Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Is pointer a data-type or what aditya Programming 63 08-07-2017 08:52 PM
data type errors microsoft/linux Programming 33 05-04-2006 10:31 PM
Data type conversion in C zaichik Programming 6 09-10-2005 05:47 PM
strange data type in c... HELP alaios Programming 9 09-03-2005 11:40 PM
Data Type 9 bob Linux - Newbie 1 02-10-2001 08:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration