473,836 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do i declare a byte variable?

hi,

I have a problem, a stupid problem. I can't declare a variable of type
byte.

The g++ said that i have syntactic error in this line. The code is
this: byte * variable;

well, i think that the mistake is a stupidity but i don't find it.
where is it?

Aug 10 '06
20 225098
On 2006-08-10 18:20:25 -0400, Frederick Gotham <fg*******@SPAM .comsaid:
Frederick Gotham posted:
>(If you're writing a positive integer literal which is larger than 65
535, then append "U" to it.)


Actually, that's only necessary if the value is greater than 2 147 483 647.

The following is guaranteed to work fine on every system:
No it isn't. There are many systems out there with a type unsigned that
can only represent values up to 65535
unsigned i = 2147483647;

The following might result in an ill-formed program on some systems
(because the signed integer literal might be out of range):

unsigned i = 2147483648;

Therefore, it's wise to append U to it:

unsigned i = 2147483648U;

--
Clark S. Cox, III
cl*******@gmail .com

Aug 11 '06 #11
Clark S. Cox III posted:
No it isn't. There are many systems out there with a type unsigned that
can only represent values up to 65535
"long" must have at least the following range:

-2147483647 through 2147483647

"unsigned long" must have at least the following range:

0 through 4294967295

Sounds like these systems you mention are not Standard-compliant.

--

Frederick Gotham
Aug 11 '06 #12
Manuel wrote:
ouch, iam stupid ;(

well, I thought about using the variable of type byte because I need to
store values from 0 to 255.
I think that i can use this:

Thomas Tutone wrote: typedef unsigned char byte;
So this way i can use byte.

Thank you for your help.

Bye.
Manuel Fernadez Campos

>>Manuel wrote:
>>>hi,

I have a problem, a stupid problem. I can't declare a variable of type
byte.

The g++ said that i have syntactic error in this line. The code is
this: byte * variable;

well, i think that the mistake is a stupidity but i don't find it.
where is it?

Standard C++ doesn't have a built-in type called "byte." Just use a
char or, possibly, an unsigned char.

Try this:

char* variable1;
unsigned char* variable2;

Or perhaps you need to tell us more about what you intend to do with
the variable.

Best regards,

Tom

Do not use a byte variable. Use a variable that is the width of the
machine's word size that will accomodate your range. Today's computers
are optimized to handle words that are more than 8-bits wide. You
should be more concerned about the correctness and reliablity of
your program than storage requirements.

For example, the ARM7 processor is designed to handle 32-bit words.
The 8-bit quantities cause more work for the processor. Saving space
is not as important as getting the program to work correctly and
delivered on time. If the program doesn't fit in its container,
then and only then, worry about the size it occupies or the memory
it requires.
At work I am battling code that has variables declared in terms
of bits, rather than "int" or "unsigned int". When the time comes
to move to a processor with larger word size, all these variables
will have to be changed. Argggh.


--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.l earn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library

Aug 11 '06 #13
Frederick Gotham wrote:
Clark S. Cox III posted:

>>No it isn't. There are many systems out there with a type unsigned that
can only represent values up to 65535


"long" must have at least the following range:

-2147483647 through 2147483647

"unsigned long" must have at least the following range:

0 through 4294967295

Sounds like these systems you mention are not Standard-compliant.
No, they are not. "unsigned" is shorthand for "unsigned int", which is
only required to represent values up to 65535.

"unsigned long" is a different type.

--
Ian Collins.
Aug 11 '06 #14
On 2006-08-10 22:23:54 -0400, Frederick Gotham <fg*******@SPAM .comsaid:
Clark S. Cox III posted:
>No it isn't. There are many systems out there with a type unsigned that
can only represent values up to 65535

"long" must have at least the following range:

-2147483647 through 2147483647

"unsigned long" must have at least the following range:

0 through 4294967295

Sounds like these systems you mention are not Standard-compliant.

Who said anything about "unsigned long"? The type in question was
"unsigned" (aka "unsigned int")

--
Clark S. Cox, III
cl*******@gmail .com

Aug 11 '06 #15
Ian Collins posted:
No, they are not. "unsigned" is shorthand for "unsigned int", which is
only required to represent values up to 65535.

We were referring to usigned integer types (note the plural).

--

Frederick Gotham
Aug 11 '06 #16
Clark S. Cox III posted:
Who said anything about "unsigned long"? The type in question was
"unsigned" (aka "unsigned int")

I see where the confusion stems from. I initially said that the following
is fine:

unsigned i = 2147483647;

What I meant was that it is not ill-formed, nor does it invoke undefined
behaviour. (However, it would have been more intuitive had I written:

long unsigned i = 2147483647;

The point I was trying to make is that the following statement is ill-
formed:

long unsigned i = 2147483648;

, because a program is ill-formed if it contains an integer literal which
is out of range. We must explicitly make the literal unsigned:

long unsigned i = 2147483648U;

You are correct, however, that the max range of "unsigned int" is not
obliged to exceed 65535.

--

Frederick Gotham
Aug 11 '06 #17
Frederick Gotham wrote:
Ian Collins posted:

>>No, they are not. "unsigned" is shorthand for "unsigned int", which is
only required to represent values up to 65535.

We were referring to usigned integer types (note the plural).
Nonsense, you said:
The following is guaranteed to work fine on every system:

unsigned i = 2147483647;
Which is false and was corrected by Clark.

You then said:
>"unsigned long" must have at least the following range:

0 through 4294967295

Sounds like these systems you mention are not Standard-compliant.
Singular and very specific.

--
Ian Collins.
Aug 11 '06 #18
Ian Collins posted:
>We were referring to usigned integer types (note the plural).
Nonsense, you said:
>The following is guaranteed to work fine on every system:

unsigned i = 2147483647;

Which is false and was corrected by Clark.

I explained this elsethread. The following statement is neither ill-formed,
nor does it invoke undefine behaviour (hence fine):
unsigned i = 2147483647;

--

Frederick Gotham
Aug 11 '06 #19
It occurred to me that Frederick Gotham wrote in comp.lang.c++:
Howard posted:

The extra efficiency of "unsigned int" is worth the cost of using up
another three bytes (or thereabouts).
Utter nonsense. There are plenty of reasons and plenty of applications
where you *do* want to use a char if possible, and where it would even
be *faster*.
>
Even if I were to write:

char unsigned i = 255;

, then it would still probably consume 4 bytes (or thereabouts) on most
systems.
*most* systems? Nonsense. Only on systems with a severe alignment problem.
While there might be processors out there which do suffer from this, they
are most definately NOT common.
(If you have a system which can only access 4 bytes of memory at a
time, rather than one sole byte, then it would be efficient to store the
byte value in the least significant byte of the 4 bytes, and to just ignore
the values of the subsequent 3 bytes).
1) Those systems, should they exist, are rare.
2) It would only be "efficient" from a minimum-execution-time point of view.
It's grossly inefficient regarding memory usage.
>
An easy test for this is the following:

#include <stdio.h>

int main(void)
{
struct FourBytes { char a,b,c,d; };

switch(sizeof(s truct FourBytes))
{
case sizeof(char[4]):
puts("Packed nice and tight!");
break;
This "proves" nor disproves absolutely nothing.
Notwithstanding any of this, your char is going to be promoted to int every
time you lay a finger on it.
Nonsense. Again.

--
Martijn van Buul - pi**@dohd.org - http://www.stack.nl/~martijnb/
Geek code: G-- - Visit OuterSpace: mud.stack.nl 3333
The most exciting phrase to hear in science, the one that heralds new
discoveries, is not 'Eureka!' (I found it!) but 'That's funny ...' Isaac Asimov
Aug 13 '06 #20

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

Similar topics

1
8240
by: Wajih-ur-Rehman | last post by:
I am using the following query: query = "insert into SystemEventsProperties (ID,PName,PValue) values (@id,@pName,@pValue)"; OdbcParameter param1 = new OdbcParameter(); param1.DbType = DbType.Int32; param1.ParameterName = "@id"; param1.Value = maxId;
41
10683
by: Miguel Dias Moura | last post by:
Hello, I am working on an ASP.NET / VB page and I created a variable "query": Sub Page_Load(sender As Object, e As System.EventArgs) Dim query as String = String.Empty ... query = String.Format("SELECT * FROM dbo.documents WHERE ") & query End Sub
24
1625
by: Desmond Cassidy | last post by:
Hi, I don't know whether this is the correct place to ask this question..anyway here goes... I have a large solution with about 300 .vb files split into 9 projects VB.net Framework 1.1 WinXP Pro Whilst editing, as soon as I try and enter a statement like Private strName as string
1
2850
by: Pucca | last post by:
I have a string, "-1608" that I need to append to a byte variable. How can I convert the string to a byte so I can append it? thanks. -- Thanks.
15
3005
by: esha | last post by:
I need to have a Public variable in my project. In VB it can be declared in a standard module. Where can I do it in C# ? I tried to do it in default class Program.cs and I tried it in an added by me class. No success So, how and where I declare a variable visible by any module in the project? Esha
2
1325
by: NiteshR | last post by:
Hi, I want to declare a variable outside a loop. The variable then needs to change everytime it runs within the loop. example: DataRow name; //Once in the for loop, the variable name must change to
1
2791
by: ares.lagae | last post by:
- I have a typelist and I want to declare a member variable for each of the types. How can I do that? E.g. I have the typelist "typedef boost::mpl::vector<int, float> types;" and I want to declare member variables with type "int" and "float". - I have a typelist and I want to declare a variable based on each of the types types. How can I do that? E.g. I have the typelist "typedef boost::mpl::vector<int, float> types;" and I want to...
1
2877
by: adz1809 | last post by:
I'm having a problem with updating a record through a form. Here is the error: Server Error in '/AccoEndUser' Application. -------------------------------------------------------------------------------- Must declare the variable '@Title'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
1
1469
by: lokesh kumar | last post by:
where and how to declare global variable in vb2005 ? EggHeadCafe - .NET Developer Portal of Choice http://www.eggheadcafe.com
0
9813
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9664
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10539
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
10584
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
9367
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
6976
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
5645
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...
0
5815
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4006
muto222
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.