Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your help!

We need 1 more developer from Canada and 12 more from Australia to help us complete a research survey.

Support our site by taking a quick sponsored survey and win a chance at a $50 Amazon gift card. Click here to get started!


Member Since 23 Apr 2003
Offline Last Active Yesterday, 05:19 AM

Posts I've Made

In Topic: lame question how to delete something from vector

30 August 2015 - 04:03 PM

If only there were a website built entirely around answering simple programming questions and only if there were a place you could go to ask questions and have the entire Internet scoured for answers in a matter of milliseconds. smile.png

1) Google: how to delete from vector by index c++

2) Very first result: (stackoverflow.com) How to erase element from std::vector<> by index?


Granted this question should be in the Beginner forum, but that said often beginners don't even know what to search for.

In Topic: C++ | Storing different types in a unordered_map

23 August 2015 - 10:04 PM

Not that I'd suggest using them for an ECS system, but there are options for dynamic types beyond standard inheritance.  boost::variant and boost::any are two examples.

In Topic: C++ | Fixed Byte Size

20 August 2015 - 10:28 AM


I as well have never seen it documented anywhere that...


When it comes to what the compiler MUST do, the only authoritative source is the language standard, not other documentation, books, or web sites.


I've always felt it was odd how few programmers even know about the C and C++ language standards, and how even fewer of them have ever read them.



In many cases even the standard isn't quite clear.  I've read through large sections of the C++ standard.  Its what, 1400 pages now?  It is not easy reading and this is coming from someone who's favorite book is Finnegan's Wake.

In Topic: C++ | Fixed Byte Size

19 August 2015 - 11:22 PM

Even these suggestions for uin16_t and such are technically wrong. The C/C++ standard does not guarantee that sizeof(uint16_t) == 2. It only guarantees that uint16_t is big enough to hold at least 16 bits. It may in fact be that you're running on an architecture that doesn't support 16-bit memory stores, so uint16_t is actually 32 bits. It may be that you're running on an architecture with 16-bit bytes so sizeof(uint16_t) == 1.


I'm not sure that's true.  http://pubs.opengroup.org/onlinepubs/9699919799/ seems quite clear that the uint8_t/int8_t etc... are exact width integers and that if these types don't exist that they would not be defined.


For each type described herein that the implementation provides, the <stdint.h> header shall declare that typedef name and define the associated macros. Conversely, for each type described herein that the implementation does not provide, the <stdint.h> header shall not declare that typedef name, nor shall it define the associated macros. An implementation shall provide those types described as required, but need not provide any of the others (described as optional).


You can also use the boost::endian types, to my knowledge they have guaranteed packing and alignment.  They even go into a little more detail here: http://www.boost.org/doc/libs/1_59_0/libs/endian/doc/arithmetic.html.  As long as you have a few proper static_assert's to ensure a compile-time error if the compiler does something funny, I don't see any problem with using these types for IO.


Granted given his apparent level of expertise I'd agree with you that its probably not the best way to go.

In Topic: C++ | Fixed Byte Size

19 August 2015 - 08:15 PM

I didn't know that C++ compilers do use padding for their structs. My mind was already blown when I encountered this with HLSL.
How can I ensure that it is packed as one unit without padding? I am looking forward to support Linux and Windows.

The problem with "cstdint" is that it only offers datatypes with 8 bytes or more (correct me if this is wrong). 

PKWare defined their ZIP-Headers using 4 and 2 Bytes.

I really don't want to use bitsets or "high/low orders".


The number at the end (uint8_t, int16_t, etc...) is the number of BITS not the number of bytes.  So on a x86/x64 machine BYTE = uint8_t = 1 byte, WORD = uint16_t = 2 bytes, DWORD = uint32_t = 4 bytes, QWORD = uint64_t = 8 bytes.