Which are variable by " Uint "? is that there are " Uint8 ", " Uint16 ", etc ...
But what are they ?
Now I have some time using C ++ but I have never needed to use these variables and cause me curious.
Thanks in advance.
uint is not a standard type. On some system uint is typedefed as
typedef unsigned int uint ;
uint is not a basic data type as mentioned in the standard. Sometimes, to make a variable to have constant size across platform [to enable portability], some typedefs are used.
You can have a look at cstdint header for more info.
With best assumption, uint should be a typedef to uint32_t
typedef uint32_t uint;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned long uint32_t;
typedef signed char int8_t;
typedef signed short int16_t;
typedef signed long int32_t;
It can help you..
if you are dealing with variable base on it's size then you can declare it like this
Related
I'm curious with the difference with SIZE_T and unsigned long.
When I saw sizeof(SIZE_T), I trace that through declaration tracing in VS.
Then, I watched them in basetsd.h file.
typedef ULONG_PTR SIZE_T, *PSIZE_T;
typedef _W64 unsigned long ULONG_PTR, *PULONG_PTR;
what's difference with them?
And why c language divide them?
SIZE_T is a Windows datatype, not a standard type. As for the difference, it is that SIZE_T may not be an unsigned long. Take a look at this page which lists Windows datatypes. The entry for SIZE_T says:
The maximum number of bytes to which a pointer can point. Use for a
count that must span the full range of a pointer.
This type is declared in BaseTsd.h as follows:
typedef ULONG_PTR SIZE_T;
And ULONG_PTR has the following entry:
An unsigned LONG_PTR.
This type is declared in BaseTsd.h as follows:
#if defined(_WIN64)
typedef unsigned __int64 ULONG_PTR;
#else
typedef unsigned long ULONG_PTR;
#endif
So it could be unsigned long, or it could be unsigned __int64. In your case ULONG_PTR and in turn SIZE_T are defined as unsigned long but this may not always be the case.
In your specific case, ULONG_PTR is defined as _W64 unsigned long, however I believe this is identical to unsigned __int64.
I tried searching quite a bit but could not find the answer. What is the size of integer variables in CPLEX? Is it 64-bit or is it arbitrary precision based on the bounds?
public IloIntVar(IloEnv env, IloInt vmin=0, IloInt vmax=IloIntMax, const char * name=0)
The Max Value of an integer decision variable is IloIntMax
PS:
dvar int x;
subject to
{
}
execute
{
writeln(x.UB);
}
gives the exact value
2147483647
code in in concert/include/ilconcert/ilosys.h
typedef __int64 IloInt;
typedef unsigned __int64 IloUInt;
typedef long IloInt;
typedef unsigned long IloUInt;
typedef double IloNum;
typedef float IloShortNum;
typedef IloInt IloBool;
typedef void* ILO_MAY_ALIAS IloAny;
typedef IloNum (*IloNumFunction)(IloNum);
IloNum is double
IloBool/IloInt both are long
Go easy on me, I'm still a newb with C/C++.. I know this has been asked a few times, and I've tried following the solutions given to no avail. This code is for a NetBurner processor, DWORD is 32 bit unsigned, WORD is 16 bit unsigned.
header func.h:
class funcs
{
// ...
private:
void myfunc();
WORD data001;
DWORD data002[100];
DWORD data003[100];
// ...
}
I have this function that calls upon that data in my class, funcs.cpp. Assume all variables have been initialized:
void funcs::myfunc()
{
data001++;
data002[data001] = x; // random x for this example
data003[data001] = y;
}
My compiler is complaining: "error: invalid types 'DWORD[WORD] for array subscript". I've changed the array subscript type to "int", "unsigned int" and every other type I could think of, and still get the error. I tried the solutions given in previous posts:
void funcs::myfunc()
{
data001++;
this->data002[data001] = x; // random x for this example
this->data003[data001] = y;
}
but it was to no avail. I've also tried containing myfunc definition within the class, same error. Any ideas/solutions? I'm stumped. Thanks guys!!
Edit: data types provided in a header file:
typedef unsigned char BOOL;
typedef unsigned char BOOLEAN;
typedef unsigned char BYTE; /* Unsigned 8 bit quantity */
typedef signed short SHORT;/* Signed 16 bit quantity */
typedef unsigned short WORD; /* Unsigned 16 bit quantity */
typedef unsigned long DWORD;/* Unsigned 32 bit quantity */
typedef signed long LONG; /* Signed 32 bit quantity */
typedef volatile unsigned char VBOOLEAN;
typedef volatile unsigned char VBYTE; /* Unsigned 8 bit quantity */
typedef volatile short VSHORT; /* Signed 16 bit quantity */
typedef volatile unsigned short VWORD; /* Unsigned 16 bit quantity */
typedef volatile unsigned long VDWORD; /* Unsigned 32 bit quantity */
typedef volatile signed long VLONG; /* Signed 32 bit quantity */
Screenshot:
Your real code (transcribed from the screenshot) is:
DWORD u_data002;
WORD u_data003;
u_data002[u_data_003] = whatever;
which tries to index an integer as if it were an array or pointer.
Presumably, either u_data002 is supposed to be an array, or you meant to write something other than u_data002.
I was wondering what is the difference between uint32_t and uint32, and when I looked in the header files it had this:
types.h:
/** #brief 32-bit unsigned integer. */
typedef unsigned int uint32;
stdint.h:
typedef unsigned uint32_t;
This only leads to more questions:
What is the difference between
unsigned varName;
and
unsigned int varName;
?
I am using MinGW.
unsigned and unsigned int are synonymous, much like unsigned short [int] and unsigned long [int].
uint32_t is a type that's (optionally) defined by the C standard. uint32 is just a name you made up, although it happens to be defined as the same thing.
There is no difference.
unsigned int = uint32 = uint32_t = unsigned in your case and unsigned int = unsigned always
unsigned and unsigned int are synonymous for historical reasons; they both mean "unsigned integer of the most natural size for the CPU architecture/platform", which is often (but by no means always) 32 bits on modern platforms.
<stdint.h> is a standard header in C99 that is supposed to give type definitions for integers of particular sizes, with the uint32_t naming convention.
The <types.h> that you're looking at appears to be non-standard and presumably belongs to some framework your project is using. Its uint32 typedef is compatible with uint32_t. Whether you should use one or the other in your code is a question for your manager.
There is absolutely no difference between unsigned and unsigned int.
Whether that type is a good match for uint32_t is implementation-dependant though; an int could be "shorter" than 32 bits.
I am programming in linux, which is new to me. I am working on a project to design a 'layer 7' network protocol, and we have these packets that contain resources. And depending on the type of resource, the length of that resource would be different. I am kind of new to C/C++, and am not sure I understand unions all that well. The idea was that I would be able to make a "generic resource" type and depending on what resource it was I could just cast a void* as a pointer to this typedef structure and then call the data contained in it as anything I please and it would take care of the 'casting'. Anyways, here is what I came up with:
typedef struct _pktresource
{
unsigned char Type; // The type of the resource.
union {
struct { // This is used for variable length data.
unsigned short Size;
void *Data;
};
void *ResourceData; // Just a generic pointer to the data.
unsigned char Byte;
char SByte;
short Int16;
unsigned short UInt16;
int Int32;
unsigned int UInt32;
long long Int64;
unsigned long long UInt64;
float Float;
double Double;
unsigned int Time;
};
} pktresource, *ppktresource;
The principal behind this was simple. But when I do something like
pktresource.Size = XXXX
It starts out 4 bytes into the structure instead of 1 byte. Am I failing to grasp a major concept here? Because it feels like I am.
EDIT: Forgot to mention, when I reference
pktresource.Type
It starts at the beginning like its supposed to.
EDIT: Correction was to add pragma statements for proper alignment. After fix, the code looks like:
#pragma pack(push)
#pragma pack(1)
typedef struct _pktresource
{
unsigned char Type; // The type of the resource.
union {
struct { // This is used for variable length data.
unsigned short Size;
unsigned char Data[];
};
unsigned char ResourceData[]; // Just a generic pointer to the data.
unsigned char Byte;
char SByte;
short Int16;
unsigned short UInt16;
int Int32;
unsigned int UInt32;
long long Int64;
unsigned long long UInt64;
float Float;
double Double;
unsigned int Time;
};
} pktresource, *ppktresource;
#pragma pack(pop)
Am I failing to grasp a major concept here?
You're missing knowledge of structure alignment. Basically, it forces certain fields to be aligned by > 1 byte boundaries depending on their size. You can use #pragma to override this behavior, but that can cause interoperability issues if the structure is used anywhere outside your application.
I think the problem is alignment. By default most compilers align to the word size of the machine / OS, in this case 32 bits / 4 bytes. So, since you have that unsigned char Type field up front, the compiler is pushing the Size field to the next even 4 byte boundary.
try
#pragma pack 1
ahead of you structure definitions.
I don't know what compiler you are using, but that's good old-fashioned C code that's been regularly in use for network programming since before most of these rude kids on StackOverflow were born.