portability

Should I expect that upcasts and downcasts in single inheritance don't adjust the pointer?

别来无恙 提交于 2019-12-10 14:49:22
问题 Suppose I have: class Base { public: virtual void Nothing() {} }; class MiddleDerived : public Base { virtual void Nothing() {} }; class Derived : public MiddleDerived { virtual void Nothing() {} }; and my code goes like this: Derived* object = new Derived(); Base* base = object; //implicit conversion here void* derivedVoid = object; void* baseVoid = base; Should I expect that baseVoid == derivedVoid ? I know that most implementations work this way but is it guaranteed? 回答1: What you "should

Portable SQL to determine if a table exists or not?

寵の児 提交于 2019-12-10 14:42:50
问题 Is there a portable way of determining if a database table already exists or not? 回答1: Portable? I don't think so. Maybe the closest you can get is: select * from <table> And this would return an error if the table doesn't exist. 回答2: This is as portable as it gets, sadly: select count(*) from information_schema.tables where table_name = 'tablename' and table_schema = 'dbo' This definitely works on SQL Server, MySQL, and Postgres. Not so much on Oracle, though. You'd have to access the Oracle

How to link old C code with reserved keywords in it with C++?

爷,独闯天下 提交于 2019-12-10 12:34:42
问题 I have a 10+ years old C library which -- I believe -- used to work just fine in the good old days, but when I tried to use it with a C++ source (containing the main function) the other day I ran into some difficulties. Edit: to clarify, the C library compiles just fine with gcc , and it generates an object file old_c_library.o . This library was supposed to be used in a way so that the C header file old_c_library.h is #include d in your main.c C source file. Then your main C source file

Serializing cyclic object references using DataContractSerializer not working

戏子无情 提交于 2019-12-10 10:17:11
问题 I'm building an XNA game and I'm trying to save game/map etc. state completely, and then be able to load and resume from exactly the same state. My game logic consists of fairly complex elements (for serializing) such as references, delegates etc. I've done hours of research and decided that it's the best to use a DataContractSerializer that preserves the object references. (I also got around for delegates but that's another topic) I have no problem serializing and deserializing the state, re

What's a portable way of converting Byte-Order of strings in C

佐手、 提交于 2019-12-09 22:35:23
问题 I am trying to write server that will communicate with any standard client that can make socket connections (e.g. telnet client) It started out as an echo server, which of course did not need to worry about network byte ordering. I am familiar with ntohs, ntohl, htons, htonl functions. These would be great by themselves if I were transfering either 16 or 32-bit ints, or if the characters in the string being sent were multiples of 2 or 4 bytes. I'd like create a function that operates on

Java Desktop Application using SQLite installed by a single installer

杀马特。学长 韩版系。学妹 提交于 2019-12-09 18:21:47
问题 I am a beginner in programming Java Desktop Application interacting with databases. My goal is to make a simple java application which uses a database to store it's data locally. After some googling I found that SQLite/Derby would cover my needs. I've googled SQLite and Derby and I found that in order to use them I need to install them on the computer through commands in terminal. My question is how the application could be done so that at the end the client will be given a simple installer

Default file extension of the executable created by g++ under Cygwin vs Linux

南笙酒味 提交于 2019-12-09 16:26:29
问题 I've done most of my work on VisualStudio and don't have much experience with gcc or g++. When I tried to compile a (ex. aprogram.cpp) this morning on my pc using cygwin, I got (aprogram.exe) when I tried to compile the same thing on my Ubuntu box I got (aprogram) w/o any extension. I am just wondering if someone be kind enough to tell me why. This question is just out of curiosity. :) Thanks in advance! EDIT: (from Jimmy's comment) g++ under Cygwin defaults to .exe 回答1: That's easy: on UNIX,

Getting meaningful error messages from fstream's in C++

若如初见. 提交于 2019-12-09 14:23:31
问题 What is the best way to get meaningful file access error messages, in a portable way from std::fstreams ? The primitiveness of badbits and failbits is getting to be bit annoying. I have written my own exception hierarchies against win32 and POSIX before, and that was far more flexible than the way the STL does it. I am getting "basic::ios_clear" as an error message from the what method of a downcasted catch ( std::exception ) of a fstream which has exceptions enabled. This doesn't mean much

int vs size_t on 64bit

孤人 提交于 2019-12-09 08:05:59
问题 Porting code from 32bit to 64bit. Lots of places with int len = strlen(pstr); These all generate warnings now because strlen() returns size_t which is 64bit and int is still 32bit. So I've been replacing them with size_t len = strlen(pstr); But I just realized that this is not safe, as size_t is unsigned and it can be treated as signed by the code (I actually ran into one case where it caused a problem, thank you, unit tests!). Blindly casting strlen return to (int) feels dirty. Or maybe it

How to do portable 64 bit arithmetic, without compiler warnings

↘锁芯ラ 提交于 2019-12-09 07:59:09
问题 I occasionally use 64 bit arithmetic in an open source C++ library of mine. I discovered that long long serves my purpose quite nicely. Even some 10 year old solaris box could compile it. And it works without messing around with #defines on Windows too. Now the issue is I get complaints from my users because they compile with GCC -pedantic settings, and GCC insists on issuing warnings that long long is not part of the C++ standard. This is probably right, but I am not too interested in the C+