C++ :: Struct Alignment Across Compilers And Operating Systems

Oct 5, 2013

I am working on extending an application that features a (rather old) plugin system. The plugin system is designed to work on x86 only, but support any and all compilers on windows, linux and also OSX.

My goals are now to

1) extend the plugin framework in a backwards compatible way
2) port it elegantly to x64

So far so good.

The plugin subsystem essentially exports a bunch of SDK function like this:

Code:
extern "C" CDECL int somefunc(int a, int b);

Which can be used by the plugin, and expect the plugin to export some function in return. When a struct is supposed to be send to the plugin, the syntax of the system goes like this:

Code:
extern "C" CDECL int RequestStructField(int field, int structhandle);

So the struct isnt handed over via a pointer, but every field has to be requested individually! From what I can tell from the comments, the developer was afraid there might be problems exchanging structs between different compilers, alignment and all.

I would like to tear down this limitation, and pass pointers to structs to plugin directly. Or better: allow the plugin to give me a pointer to an empty struct which i subsequently fill.

However, i have no control over the compiler or language used to write the plugins. Quiet some plugins are written in Delphi, some even in MASM ... both would have to support this way of passing structs.

the question is: does that work?

I have looked at other plugin systems, but they either use entirely different ways (XPCOM) or are limited to a single platform or compiler.

Some of them have a note stating that the plugin must be compiled with "byte-aligned" structs.

x86 and x64 plugins are two different stories, x64 version of the app does NOT have load x86 plugins. I dont expect there to be too man problems (right?). But we'll see, i guess.

View 13 Replies


ADVERTISEMENT

C++ :: System That Communicates With Other Systems Via Messages - Struct Member Manipulation

Dec 5, 2012

I work on a system that communicates with other systems via messages. Those messages are defined in a spec and every word must be exactly as defined. To accomplish this Ada allows me to define the fields of my record to specific words in memory.

Code:
word = 4;
type Msg_Type1 is record
x: Some_Type;
y: Another_Type;
z: Another_Type;
end record;

[Code] ....

View 5 Replies View Related

C :: Strcmp Return Value On Different Compilers

May 3, 2013

I'm having a problem with the strcmp return value. My compiler returns the correct value based on my research, but I tried to compile the code below on those online compilers and the result was 1.

My compiler gave me 10, which I consider to be the correct result according to strcmp - C++ Reference. So strcmp is not very portable?

Code:
#include <stdio.h>
#include <string.h>

int main(void) {
printf("Return value: %d
", strcmp("Rocks", "Rockie"));
return 0;
}

View 6 Replies View Related

C++ :: Number Of Compilers Installed

Dec 23, 2013

I get the feel to install and try different types of C++ Compilers. Currently I have installed:

Visual C++ 2010 (Express)
Visual C++ 2013 (Express)
MinGW-GCC
Borland C++ 5.5

So is it just me or do you too have a bunch of compilers installed?

View 6 Replies View Related

C++ :: Data Alignment Across Different Platforms

May 7, 2014

Basically, I'm working on a code that has its own allocator class. In the backend, the class uses malloc() to create huge blocks of memory aligned to sizeof(void*).

Apparently, in certain special circumstances, sizeof(void*) will be 4 when the data actually needs to be aligned to 8 bytes. If the memory isn't aligned to 8 bytes, there will be heap corruption and a bus error will occur. One such case is on HP-UX; we forced the alignment to 8 bytes on that platform. According to the commit log, HP-UX has a minimum struct size of 8 bytes and that's why it has to be aligned to 8 bytes (but I can't confirm if this is actually true).

We're running into these same problems when compiling on MIPS, MIPSel, and SPARC (all 32-bit builds).

(Side thought just now as I wrote that: seems like RISC processors don't allow unaligned access while x86 processors do. It looks like these build failures on MIPS and SPARC were while trying to build 32-bit on 64-bit hardware, could this be the problem?)

Anyway, the ultimate question and goal here is to find out how to detect this magical minimum alignment size, if not sizeof(void*).

View 9 Replies View Related

C++ :: Cannot Control Table Alignment

Nov 29, 2013

I want the function to display all accounts deposit list to work properly, what i mean is that the table coming has its contents here and there . I want to align them properly. program in comment.

View 11 Replies View Related

C++ :: How To Ask User To Input Operating Symbols

Aug 6, 2013

how to ask the user to input operating symbols like "+","-","*" and then use it to operate on the numbers. The user should be asked to input the symbols not like this

1.+
2.-
3.*

View 2 Replies View Related

C# :: Setup Not Working In Other Systems With Other SQL DB Server

Mar 7, 2014

I developed one windows application in c#.net , this application is not working when i installed the setup in another system with another sql database server-r2. How can solve this. here i had attached my code for reference.

App.config file

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="SqlCon" value="Data Source=.sqlexpress;Initial Catalog=aathi;Integrated Security=True;Pooling=False"/>
</appSettings>
</configuration>

[Code] ....

View 3 Replies View Related

C++ :: Standardizing Size Of Float Across Multiple Systems

Jan 4, 2015

I'm currently writing a cross-platform on screen keyboard application that highlights keys on the screen as you type them. My approach was to use an image of a keyboard and layer semi-transparent sprites over each key on key events, and as a consequence I needed to map out precise positions of each of these sprites relative to the background image.

The issue became how to load those positions into my application during runtime? My solution was to use excel to make a .csv of all the x-y coordinates, but instead of just deploying the .csv with my application I decided to write a quick app that parsed each line of the csv for coordinate pairs and write those floating point numbers to a binary file instead. That way the end user can't easily edit the coordinates of the sprites.

Now on to my question. The way I load the data into my application is by this method:

#include <fstream>
#include <vector>
/* other includes */
/* ... runtime code ... */
std::vector<float> pixmapPosData;

[Code] ....

This works fine on my system, but what if sizeof(float) has a different length their system? Then this function could throw a read access violation towards the end of the file (since the .bin file is exactly 508*sizeof(float) bytes long on my computer), and not to mention the coordinates would be meaningless. Is there any way to avoid this? Or maybe I just just suck it up and deploy a .csv file?

View 3 Replies View Related

C/C++ :: Operating System Written Can't Print Out Lines?

Nov 12, 2014

I'm taking an operating systems class and I'm trying to write a script that would execute a program in Simple OS.I"m not sure if this is the right place for this because although the entire OS is written in C, "asm" are assembly language code. Anyway when I run the OS in virutal box and try to run a program, I get a "Fatal Execption" in a loop until the entire OS crashes. So then I try to debug my code BUT when I add printf statements and try to run the code again I don't get to the "fatal execption" and the entire OS just crashes. 1) why can't I add print lines? 2) what's going on with the fatal execption?

////////////////////////////////////////////////////////
// Loads program and executes it in user mode
//
#include "kernel_only.h"

[Code]....

View 3 Replies View Related

C :: Printf Alignment - Prints Out Text In The Center Of Window

Jul 19, 2013

I'm trying to find out, how to do printf so that it prints out text in the center of the window. I know how left and right justifyment is... but how to get to the center? C...

View 2 Replies View Related

C/C++ :: How To Access Files Of A Computer Through Batch Operating Codes

Oct 21, 2013

How to use c programming codes or batch operating codes to access files from our computer.

View 1 Replies View Related

C/C++ :: Sizeof (struct) Returns 6 More Bytes Than Actual Struct Size?

Sep 14, 2014

#include <stdio.h>
#define MAX_USERS 20
struct {
char ID[10];
char Name[40];
int Pos;

[Code] .....

I was attempting something weired with address to move data around when I discovered that the size of the array is not what I expected. I am passing this structure as &Users to a function that declares it as a void *, then I can deal with chunks of data (memmove) and not have to worry about index or things like that. However...sizeof is returning something I do not understand.

View 9 Replies View Related

C++ :: Creating A Struct Within Struct Node?

Feb 28, 2015

Im having trouble creating a struct within a struct node. the program suppose to hold students firstname, lastname, and gpa in a node therefore creating my linked list. Line 26 keeps saying that cannot convert parameter 2 from 'studentType to std::string

#include <iostream>
#include <string>
using namespace std;
struct studentType{
string firstname;
string lastname;
double gpa;

[code].....

View 2 Replies View Related

C++ :: Accessing Inside Structure Via Struct Pointer To Struct Pointer

Jun 5, 2012

"
#include <stdio.h>
struct datastructure {
char character;
};
void function(struct datastructure** ptr);

[Code] ....

These codes give these errors:

error: request for member 'character' in '* ptr', which is of non-class type 'datastructure*'
error: request for member 'character' in '* ptr', which is of non-class type 'datastructure*'

These errors are related to
"
*ptr->character='a';
printf("Ptr: %c",*ptr->character);
"

I want to access "character" data inside the structure "trial" by a pointer to pointer "ptr" inside function "function",but I couldn't find a way to do this.

View 3 Replies View Related

C++ :: Struct Inheriting From A Class Or A Class Inherit From A Struct?

Mar 9, 2012

I just read and have known for a while that classes are private (members and inheritance) by default and structs are public. But my question then comes what if.. a struct inheriting from a class or a class inheriting from a struct?

View 3 Replies View Related

C++ :: Having Struct As A Key For A Map

Oct 24, 2014

So why does this not work? As an example:

struct example {
int x; int y;
};
int main() {
example variable;
variable.x = 1;
variable.y = 2;
map<example, int> something;
something[variable] = 3;
return 0;
}

And I get a very long error message from the compiler. I tried using an enum as the key as well and that worked just fine, but I guess that's just the same as having an integer as the key. But anyway, what's the problem with this? Is there any way to make it work?

View 4 Replies View Related

C :: How To Use Pointer To Struct

Mar 6, 2015

how can I call and print the Pointer:

ptr->address
Code: #include<stdio.h>
struct account {
int address;
int value;

[code]....

View 5 Replies View Related

C :: How To Do Search In Struct

Jul 9, 2014

So i create a simple structure,that has a firstname, lastname, age, dateofbirth.I would like it if i type what I am searching for print out there is one or not.But i have some trouble with equals(in array).. i type in the same "keresettnev" as "tanulok[i].Firstname" but it thinks not the same. (it works with age..)

Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct student {
char *Firstname[40];
char *Lastname[40];
int age;

[Code] ....

View 12 Replies View Related

C :: Why Zero Out Rest Of The Struct

Jun 19, 2014

I am using Beej's Guide to Network Programming Using Internet Sockets. I'm just curious why I need to zero out the rest of the struct?

Code:

int main(){
int sockfd;
struct sockaddr_in my_addr;
sockfd = socket(AF_INET, SOCK_STREAM, 0);

[Code].....

View 8 Replies View Related

C :: How To Printf A Struct

Apr 22, 2014

Code:

#include <stdio.h>
struct database {
int id_number;
int age;
float salary;

[Code] ....

When I compile, I get an error:
test.c|18|error: incompatible type for argument 1 of 'printf'|
note: expected 'const char *' but argument is of type 'float'|

I thought employee.salary is a float but the compiler expected 'const char'. How do I make this work?

View 4 Replies View Related

C++ :: How To Alias Struct

May 7, 2013

I am working on a program which uses external hardware to acquire data. we have the option to use hardware from two different companies, each with it's own driver. However both do the same job. My program is meant to read data packets which are structured as:

typedef struct _data {
DWORD ID;
BYTE bf;
BYTE bd;
BYTE bData[8];
DWORD bt;
} data;

Now both the companis use the same data structure, but the first has defined the structure, let's say, as:

typedef struct _dataX {
DWORD ID_X;
BYTE bf_X;
BYTE bd_X_;
BYTE bData_X[8];
DWORD bt_X;
} dataX;

[code].....

I am programming my software so as t allow the customer to use the hardware of their choice. Simply select the card they are using and our program should be able to take care of the rest of stuff. I am using #ifdef directives to include the header for the corresponding hardware dll. Now I want to define my own data struct of the type:

typedef struct _dataMY
{
DWORD ID_MY;
BYTE bf_MY;
BYTE bd_MY_;
BYTE bData_MY[8];
DWORD bt_MY;
}

[code]....

and when I use _dataMY.ID_MY .. it should directly be able to see if it is _dataX.ID_X or _dataY.ID_Y, based upon the directive I have used earlier.

View 3 Replies View Related

C++ :: Going From Struct To Class

Jun 21, 2014

I've been working on a path-tracer for some time, and all along I've used structs instead of classes for vectors and matrices. Today I changed all of them to classes instead, changing none of the actual function bodies themselves, and the results were miserable to say the least.

Here's a render form before the change: [URL] ....

And here's the same render after: [URL] ....

Why this is happening, considering that none of the actual function-bodies have been changed, except for what little is needed to make the change from class to struct.

View 5 Replies View Related

C++ :: Iterating Through Struct Members?

Apr 4, 2013

Suppose I have a struct with 20 members. I want to assign each of those structs with values. Instead of accesing by explicit convention, i.e.:

Code: struct.member1 = 1;
struct.member2 = 2;
...
...
...
struct.member20 = 6;

Is there any way to encapsulate it in a for loop and use an iterator variable to indicate the member? i.e.:

Code: for (int i = 0; i < 20; i++)
struct.i = i;

The above is pseudocode but Im sure you get what Im trying to do?

View 2 Replies View Related

C++ :: Outputting Associated Data In Struct

May 2, 2013

So this is the last part of a program I've been working on for four weeks now. This question may be a tough one considering the amount of files included in the program.

The program is to read in a file of requests between two cities, read in a file of flights and cities that occur between the cities. It then checks to see if there is a path between the flights and output an itinerary. I have the correct itinerary outputting, but when attempting to output the associated flight number and price according to the city, I am getting odd data. How can I output the correct flight number and price associated with each flight on the itinerary.

I'll post out the output I am currently getting and the section where I am outputting the data. I'm sure I'll need to post more files so the program can be understood.

Don't want the code done for me, just a point in the right direction! I don't want to let this program defeat me!

Output: Code: Request is to fly from Atlanta to San-Diego.The flight itinerary is:
Flight # From To Cost
10 Atlanta Chicago $134529069
10 Chicago Miami $134529069
10 Miami Dallas $134529069
10 Dallas San-Francisco $134529069
10 San-Francisco San-Diego $134529069
This function finds a path between cities. Code: bool flightMap::IsPath(string originCity, string destinationCity){
StackClass aStack, bStack;
flightStruct flightRec;
string topCity, nextCity;
bool success;
int index = 0;

[Code].....

View 1 Replies View Related

C :: Array Of Pointers To A Struct?

May 10, 2013

I am working on an assignment identical to another post from a couple years ago, for reference here is the thread:

array of pointers to structures sorting addresses by zip code

They way it is written on that thread is almost identical to the way the teacher implied to have it done (only wrote part of the input block). But I am having an error:

When it gets to the output section it outputs then next name along with the zip code... I tried strncpy and strxfrm but both cause more problems than they did work.

The last part of the project is to have the output put out in order of least zip code to most zip code (00000<99999), so this is causing me a real problem and I do not see what exactly is making this happen.

Here is my code (we dont HAVE to use gets but professor suggested using it for this assignment, next lab is to rewrite this using files and fgets rather than I/O redirection):

header.h Code: #ifndef lab_6b_7b_Header_h
#define lab_6b_7b_Header_h
//header file intiating other headers
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct{

[code]....

I have not started the sorting code because I cannot get past this, but once I have proper zip codes I am sure I can make a sort function no problem.

I am using xcode with some breaks to read variables as various points and do not notice anything wrong until it makes it to the output functions, although this page briefly pops up between input and output functions when the breaks are up:

View 8 Replies View Related







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