C++ :: Unreliable Sizes For Fundamental Types?

Apr 9, 2013

The size of fundamental types is not guaranteed. Apparently, all the standard guarantees is a hierarchy of sizes, and some minimum representable value range.

Specifically, a char is not guaranteed to be one byte. Also, the sizeof operator always returns 1 for the size of a char, even if the actual size is not eight bits.

Isn't this a huge problem for portability? It seems like 2+ byte characters would break all kinds of things. For example, fstream::write() takes a char * and a byte-length argument. If you ported from a 1-byte-char platform to a 2-byte platform, wouldn't that screw up all your write()s? Worse, you couldn't even detect the problem without trial and error, since sizeof would just lie to you.

I've never actually seen a platform where char wasn't 1 byte, but it sounds like a disaster waiting to happen.

View 6 Replies


ADVERTISEMENT

C++ :: Proper Fundamental Type Overloading

Feb 5, 2014

I am currently working with the fundamental types in C++, and there is some ambiguity (which I have tried to solve).

I am creating a function that needs an overload for _all_ fundamental types (in addition to a void *).

Some types overlap (like "unsigned wchar_t" and unsigned int, whilst wchar_t never overlaps), so, I would like some confirmation about my current overloads being complete and overlap-free on your system as well.

bool
char
unsigned char
signed char

wchar_t
char16_t // In fact, builtin-types, look like typedef.
char32_t

[Code] ....

To test the valid types, I have created a small test that shows which builtin types overlap and which do not.

#include <map>
#include <vector>
#include <iostream>
#include <string>
#include <typeinfo>
int main(int argc, char *argv[]) {

[Code] ....

I also wonder; what "type" is nullptr? I tried googling but no definitive answers came up. Still, it works as a valid function overload.

View 3 Replies View Related

C :: Parameter Names Without Types And Conflicting Types In Fgets

Jan 22, 2014

I have this

Code:

#include<stdio.h>
#include<ctype.h>
#include<string.h>

int check_up(char string[]);
int check_low(char string[]);
void to_up(char string[]);
void to_low(char string[]);

[Code] .....

When I compile this I have the following problems: warning: data definition has no type or storage class [enabled by default] in 'to_up(word)'conflicting types in 'to_up' function and to_low function warning: data definition has no type or storage class [enabled by default] into_up function error: unknown type name "word" in line 'printf("All uppercase %s. ", word):;'warning: parameter names (without types) in function declaration [enabled by default] in 'to_up(word)'and 'to_low(word)' 'note: previous declaration of "to_up" was here in function declaration of to_up function

View 7 Replies View Related

C++ :: Adding Two Arrays With Different Sizes

Sep 6, 2013

#include <iostream>
#include <array>
#include <sstream>

[Code].....

I need to add thevArr[I] and vArr1[I] and store in vArr2[I] but I cant figure out how to drop the value or replace with a 0 if vArr is bigger than vArr1. IE: 1st number: 123 2nd number: 4567

Ill get something like this:
1 2 3
4 5 6 7
5 7 9 -827349

View 2 Replies View Related

C# :: GTK - How To Manage Sizes Of Widgets

Aug 3, 2014

I create new dialog window. I add container Fixes and change Fixed properties : - AutoSize, +Expand, +Fill to enable other widgets. I add Text View, Textview is inside GtkScrolledWindow which has property X and Y but not Height and Width. If GtkScrolledWindow has scrollbars, its size is fixed, if not - size depends on the content Textview and grows when I type text. I want not to grow control if I type Text but want my own size. It is possible?

View 7 Replies View Related

C :: How To Declare A Group Of Arrays Of Different Sizes

Oct 15, 2013

I'm building a box to take in several arrays of different lengths. one group happens every 10 seconds. one of them happens every 5 seconds. this is from a weather station.

10 sec
subgroupA[14]
subgroupB[24]
subgroupC[17]
subgroupD[12]
subgroupE[34]

5 sec
subgroupC[17]

I plan to retransmit them, substantially unchanged at a lesser rate to save radio power over a serial data link. buried in groupD, I want to change a few chars before retransmit.

I don't want to go to the trouble of doing a structure for each of them since most will be resent unchanged. some entries are chars, some are decimal, some are a mix. I guess it might be convenient to further define groupD, maybe not.

what is the best way to declare the group? I want them to be contiguous since that's how they will end up in the tx buffer. Each subgroup has its own checksum, so I planned it this way to make checksum more convenient.

View 6 Replies View Related

C++ :: Pulling Integer Sizes Within A Function?

Feb 7, 2013

I'm trying to find the MAX and MIN integer sizes that are entered in by the users. I know that we need to sort [i] and [j] in my function to figure out which is the highest and lowest score correct?

#include <iostream>
using std::cin;
using std::cout;
using std::endl;

[Code].....

View 4 Replies View Related

C++ :: Compare Queue Sizes In A Vector?

Feb 15, 2013

I have a paradigm where a integer before gets enqueued to a queue in a vector, the loop of queues is searched and integer is enqueued to a queue which has minimum size among the queues. the following code shows the operation

#include <vector>
#include <queue>
std::vector<std::queue<int> > q

[Code].....

next i am trying to extend my paradigm with the condition, that the integers should be enqueued to the shortest queue until the count of the shortest queue is less than or equal to count of any another queues in the loop of queues.

i want to do something like the code shown below

#include <vector>
#include <queue>
std::vector<std::queue<int> > q

[Code].....

View 4 Replies View Related

C/C++ :: Two Arrays With Different Sizes Into One 2 Dimensional Vector

Mar 24, 2012

I am using 2 ARRAYS OF DIFFERENT SIZES in One 2-Dimensional Vector, and my output is not correct. The arrays are size 4 and size 13.

I want COLUMN 0 to have: 55, 66, 77, 88.

I want COLUMNs 1-12 to have 1,2,3,4,5,6,7,8,9,10,10,10,11 in EACH ROW. It would seem that the 2nd loop for the size 13 array would need to loop 4 times in order to fill 4 rows, however, I'm not sure how to do that. Here is what I have so far in code and output:

#include <iostream>    
#include <vector>  
using namespace std;  
int main() {
    int typeArray[4] = {55,66,77,88};
    int valArray[13] = {1,2,3,4,5,6,7,8,9,10,10,10,11};  

[Code] ....

OUTPUT:
55 0 0 0 0 0 0 0 0 0 0 0 0
1 2 3 4 5 6 7 8 9 10 10 10 11
77 0 0 0 0 0 0 0 0 0 0 0 0
88 0 0 0 0 0 0 0 0 0 0 0 0

How to populate rows correctly?

View 2 Replies View Related

C++ :: Generating Conversion Table For Wrench Sizes - For Loop

Feb 15, 2014

I'm writing a program where I need to generate a conversion table for wrench sizes with the following columns: Size (Inches) [Fraction], Size (Inches) [Decimal rounded to 3], Next Bigger Metric (mm), Difference (Inches) [Next Bigger Metric-Inches], Closest Metric (mm) [to original size], and Difference (Inches) [Closest Metric-Inches]. I've created the column for the Size in fraction form relatively quickly but I cant seem to produce the decimal version. Instead, I get 0.000.

Code:
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
using namespace std;

[Code] ....

View 4 Replies View Related

C++ :: Advanced Data Namespace - Exchanging Byte Sizes

Jul 27, 2013

I have an advanced data namespace in which I hope to be able to read a data variable of any type and transfer it's bytes into another type of a multiple size.

i.e.
char[4] -> int;
int -> short[2];
short -> char[2];
char[2] -> short;

but I'm having some trouble, I get the following errors (because as a template it must compile from start)

template<typename T1, typename T2> void stepBytes(UCHAR size1, UCHAR size2, T1 in, T2& out){
if(size1 == 0 || size2 == 0)
return;
if(size1 % size2 != 0 &&
size2 % size1 != 0)

[Code] ....

So, why's this error appearing?

View 2 Replies View Related

C++ :: Values Are Changing When Passing Arrays And Array Sizes?

Feb 28, 2014

I'm working on a homework assignment that asks me to roll two die a user given number of times, find the roll sums, and a few other things. I'm working on it one module at a time and I'm running into two big problems so far.

The first problem is that my int variable rolls changes to a number within the random number generator range of numbers after I run rolldie. I got around this by making a const equal to the user entered value of rolls just so that I could continue developing the program.

My second problem is that the values of the arrays resultsOne[] and resultsTwo[] are changed after running findsum(). Why this is happening and I even tried passing them as const, but that changed nothing. We just started learning about passing arrays to functions, so there might be something big that I'm missing.

Code:
#include <iostream>
#include <cstdlib>
using namespace std;
void rolldie(int resultsOne[], int sizeOfresultsOne, int resultsTwo[], int sizeOfresultsTwo);
void findsum(int resultsOne[], int sizeOfresultsOne, int resultsTwo[], int sizeOfresultsTwo, int tossSums[], int sizeOftossSums);

[Code] ....

View 8 Replies View Related

C++ :: Increase Sizes Of Queue In A Vector Of Queues And Find Shortest Queue

Feb 20, 2013

I have a paradigm in a loop of queues of a vector,if a condition is true,increase sizes of the queue of that particular queue in the loop of queues, if condition is false, the queuesize is left as such in loop of queues. After this operation i need to search the queue sizes of all queues and enqueue in the shortest queue.

I want to do something like the code given below

#include <vector>
#include <queue>
int min_index = 0;
std::vector<std::queue<int> > q
std::size_t size = q.size();

[Code] ....

How to implement this logic?

will q[i].size=q[i].size+5 increase the queuesize by 5 for the ith queue?

View 12 Replies View Related

C++ :: Using New On Primitive Data Types

Dec 12, 2014

int* count;
count = new int(1); // what???

Is this on the heap?? do i have to delete it now?

So is 'new' on a primitive data type just a way for me to allocate primitive data types (int, char, etc.) on the heap instead of the stack?

And, out of curiosity, can you do that in Java?

View 4 Replies View Related

C++ :: How To Convert Data Types

Jan 9, 2015

How to convert these data types? i have an array of bytes in unsigned char[] array, and need to convert to const void* pointer.

View 3 Replies View Related

C++ :: Operand Types Are Incompatible

Oct 14, 2013

#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

int main() {
double temp, result;
char type;

[Code] .....

View 2 Replies View Related

C++ :: Object That Contains 2 Types Of Data

May 24, 2014

How do you create an object (like in the title) something more simple than a struct? I wanna know that cuz I'm writing a function that could return a boolean and an integer at the same time.

View 2 Replies View Related

C# :: Working With Different Types And Casting?

Jan 3, 2015

double a = 1.0 + 1 + 1.0f; //everynumber will be added up as a double even the last one which is a float. All 3 numbers will turn into 3.0 as a double.

int x = (int)(7 + 3.0 / 4.0 * 2); //the variable will do the math bracket first. then the va type will still be an int because int was never changed.

Console.WriteLine((1 + 1) / 2 * 3); // 1 + 1 will be done first then 1 / 2 then * by 3
Console.WriteLine(x);
Console.ReadKey();

I THINK THATS ALL WRONG ^ =/ like the comments

double a = 1.0 + 1 + 1.0f;

In this equation, everything is using addition, so we start working left to right. 1.0 + 1 is the first step. These two representations of 1 aren't the same type though. In fact, none of the three are.

The first is a double, the second is an int, and the last is a float.

So in order to do 1.0 + 1, we need to convert one type to another. Since the double type is "wider" than the int type, we'll move things up to the double type. We'll convert the int version to a double, and to 1 + 1 using double types, resulting in 2.0 as a double.

Next we do the other addition. This has the same problem, though, because we'll be adding our result from the first step (a 2 as a double) to a float. So again, the float gets converted up to a double and we do the addition using doubles.

We now have a value of 3 that is the double type, which we can simply store in our a variable without any conversions at all, since our value is already a double type.

View 4 Replies View Related

C/C++ :: ISO Forbids Comparison Between Ptr And Int For Types

Jul 14, 2014

This is some code that simulates files and directories the same way an operating system does so. I commented out every std::string occurrence because I got the :

terminate called after throwing an instance of 'std::length_error'
what(): basic_string::_S_create

View 3 Replies View Related

C++ :: Passing Types To Functions

Jan 12, 2013

I've got a game engine with a line-trace collision method which returns the first object it hits. I'd like to be able to pass it a class-type so that it can ignore objects of other types.

consider this pseudo-code:

Entity* TraceEntity( const Vec3f& LineStart, const Vec3f& LineEnd, const Type atype ) {
// check collision on entities, ignore entities of type 'atype'.
// return whatever it finds
}

I'd like to do this without template classes because it will result in a significant bloat in executable size every time I decided to trace for a new entity type (I've really developed a distaste for templates for this reason)

using type_info only checks for an object's deepest subclass, so it won't work for class C : public B : public A if I'm looking for classes of type B.

View 5 Replies View Related

C Sharp :: What Are Different Types Of Interfaces

Jul 11, 2013

he was asking various types of implementing interfaces in csharp,

View 1 Replies View Related

C/C++ :: Instantiate Template For Certain Types

Dec 17, 2012

Is there a way in either Visual Studio 2010 or g++ (any version) to see what classes it instantiates and their code? For example to see if i avoid code bloat when i explicitly instantiate a template for certain types.

View 3 Replies View Related

C++ :: What Are The Implications Of Declaring Data Types But Never Using Them

Mar 26, 2013

What are the possible problems if I declare a bunch of data types and never use them? Do they take up a lot of memory? Will they slow run time? If it is an array do I have to delete it at the end of the program? What if the array is defined inside a class and never used? Do I still have to delete it?

i.e.

Code: class declarearrays{
public:
double **darray;
double **darray2;
void function1();//function that initializes darray
void function2();//function that initializes darray2 with different parameters, may not be used.
};

View 1 Replies View Related

C :: Error - Incompatible Types In Assignment

Oct 11, 2013

I am working on a double linked list and inside of my function to insert a node, I am getting an error of "Incompatible types in assignment". Here is my function code. Line 55 is where I am receiving the error.

Code:

45 struct lnode *ins_llist(char data[], struct llist *ll){
46 struct lnode *p, *q;
47
48 q = malloc(sizeof(struct lnode));
49 if ( q == NULL )

[Code]....

View 2 Replies View Related

C :: Conflicting Types Error When Compiling A Lib

Dec 24, 2014

I'm trying to compile a library for use with PoLabs Pokeys 56U USB device (PoKeys56U) on Linux Mint 17 64-bit.

I'm using the information from here - New cross-platform library for all PoKeys devices - MyPokeys

When I run

sudo make -f Makefile.noqmake install

I get the following errors;In file included from PoKeysLibCore.c:22:0:

PoKeysLib.h:38:28: error: conflicting types for "int64_t"
typedef long long int64_t;
^
In file included from /usr/include/stdlib.h:314:0,
from PoKeysLibCore.c:21:

[Code] ....

Here is the offending code from the header file;

Code:
#ifndef __POKEYSLIB
#define __POKEYSLIB
#define USE_STD_INT

#ifdef USE_STD_INT
#include "stdint.h"

[Code] ....

View 12 Replies View Related

C :: Errors For Incompatible Types In Return

Oct 23, 2013

I am writing a program in C. The following is an extract from my code:

Code:

enum coin_types{
FIVE_CENTS=5,
TEN_CENTS=10,
TWENTY_CENTS=20,
FIFTY_CENTS=50,
ONE_DOLLAR=100,
TWO_DOLLARS=200

[Code] .....

I'm getting the following errors:

For: new = new_coins_data_line(line);
"Incompatible types in assignment"

For: return newdata;
"Incompatible types in return"

There seem to be problems with my variables and perhaps it is related to the type 'struct coin' which has an enumerated type within it.

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved