c++

Can __attribute__((packed)) affect the performance of a program?

I have a structure called log that has 13 chars in it. after doing a sizeof(log) I see that the size is not 13 but 16. I can use the __attribute__((packed)) to get it to the actual size of 13 but I wonder if this will affect the performance of the program. It is a structure that is used quite frequently. I would like to be able to rea...

c++ screen shot

umm i know this can be done but no idea how to...how to capture screen shot using c++,im gonna be working with win32. please no mfc code... thanks Rami ...

problem in understanding the code

i = 0; while (fscanf(fp, "%f %f %d", &x[i], &y[i], &outputs[i]) != EOF) { if (outputs[i] == 0) { outputs[i] = -1; } i++; } patternCount = i; I dont understand the meaning of this line from the above code: if (outputs[i] == 0) { outputs[i] = -1; What does it represent. The Output is a matrix or vector.?? ...

Question regarding dequeues and testing

Hello guys, I am preparing for an interview and I came across these questions. Can some one please help how to solve these questions. Imagine you've 2D system which is just testing whether 2 rectangles are in collision state or not, and you supposed to make a program which takes the code of this system from its developers and test it ...

Serial Port communication with Arduino and C++

Hi, I am having a problem with a Serial Port communication between Arduino Nano and C++, even though the problem is in C++ side. Basically I want to send integers (or long,...) from the Arduino to a C++ program to be processed. First I did a test sending information from the Arduino to the computer using Matlab. The Arduino code is pr...

How Do Vector drawing applications do this?

In Illustrator, you can drag a rectangle and it will select all objects in it. It does beyond a bounding box test since it ensures its touching an actual part of the polygon. How does it efficiently do this then? (A C or C++ implementation would be preferable) Thanks ...

whats the difference between C strings and C++ strings?

whats the difference between C Strings and C++ strings. Specially while doing dynamic memory allocation ...

Sharing data with a dynamically loaded library (dlopen,dlsym)

My main program would load a simple dynamic library called hello.so In main void* handle = dlopen("./hello.so", RTLD_LAZY); In main , pass a callback function called testing (defined somewhere in main.h) and invoke the hello() from the dynamic library typedef void (*callback)(); typedef void (*hello_t)( callback); /* do somet...

How are structs laid out in memory in C++?

Is the way C++ structs are laid out set by the standard, or at least common across compilers? I have a struct where one of its members needs to be aligned on 16 byte boundaries, and this would be easier if I can guarantee the ordering of the fields. Also, for non-virtual classes, is the address of the first element also likely to be th...

Why does a pointer's allocated memory persist after a function, but not an array?

So, I ask this question in the context of a basic text input function I see in a C++ book: char *getString() { char temp[80]; cin >> temp; char * pn = new char[strlen(temp + 1)]; strcpy(pn, temp); return pn; } So temp declares an array of 80 chars, an automatic variable whose memory will be freed once getString() r...

Find/Replace Using C++ Macro?

I have a case where I'm using a macro to generate simple subclasses. I've currently got it defined as: #define REGISTER( TYPE, NAME ) \ struct NAME ## Class : public ParentClass \ { \ NAME ## Class () : ParentClass ( # NAME ); \ } I really want t...

C++ strange socket data

Hey guys, here is my code. int main() { char buffer[BUFSIZE]; // define our address structure, stores our port // and our ip address, and the socket type, etc.. struct sockaddr_in addrinfo; addrinfo.sin_family = AF_INET; addrinfo.sin_port = htons(PORT); addrinfo.sin_addr.s_addr = INADDR_ANY; /...

Trying to use static methods/members, need some help

Hello, I've been spoilt with c# coding the last few years and now I'm back onto c++ and finding that I'm having trouble with stuff that is supposed to be simple. I'm using a third party library for gamedev called DarkGDK (any commands which are prefixed with db), however DGDK isn't the problem. Heres my code: System.h #pragma once #...

How do I duplicate certificate authentication (Mumble (c/c++)) in Python?

Alright so, before I really get into this post, I am going to have to warn you that this might not be an easy fix. Whoever reads and is able to reply to this post must know a lot of c/c++, and at least some python to be able to answer the question I have above. Basically, I have a connection method from Mumble (a VOIP client), that con...

How to use boost::object_pool<>::construct with a non const reference as a ctor parameter?

Is it somehow possible to use boost::object_pool<>::construct with non const references? The following snippet doesn't compile (VS2010): foo::foo(bar & b) { } static boost::shared_ptr<foo> foo::create(bar & b) { return boost::shared_ptr<foo>(foo_pool.construct(b), boost::bind(& boost::object_pool<foo>::destroy, & foo_pool, _1));...

The order of data in memory

A few simple questions. const int gFirst; const int gSecond; struct Data { static int First; static int Second; int first; int second; }; Data data; Is it guaranteed that the following statements are true? 1) &gFirst < &gSecond 2) &Data::First < &Data::Second 3) &data.first < &data.second ...

File operation in C++

I have written an object to file but when i read the object from the file is not getting the correct value. if 1 object is considered as 1 record if only 1 record is there in the file its getting the value. if i write more record (many object of same type) then its not getting the value. plz help me what to do. ...

Generic method to display enum value names

Is there a way to display the name of an enum's value? say we have: enum fuits{ APPLE, MANGO, ORANGE, }; main(){ enum fruits xFruit = MANGO; ... printf("%s",_PRINT_ENUM_STRING(xFruit)); ... } using the preprocessor #define _PRINT_ENUM_STRING(x) #x won't work as we need to get the value of the variable 'x' and then c...

Wrong value generated from math equation using a preprocessor directive

I have this preprocessor directive: #define INDEXES_PER_SECTOR BYTES_PER_SECTOR / 4 where BYTES_PER_SECTOR is declared in another header file as: #define BYTES_PER_SECTOR 64 I have this simple math equation that I wrote where after executing I get an assertion error as the value assigned to iTotalSingleIndexes is incorrect. int...

C++ return vector, can't figure out what's wrong

The following program keeps crashing and I can't figure out what's wrong. It seems that v is somehow not available in the main function.. #include <iostream> #include <vector> using namespace std; vector<string> *asdf() { vector<string> *v = new vector<string>(); v->push_back("blah"); v->push_back("asdf"); return v; } ...