C/C++ :: Preprocess Source To Automatically Set Structure Field
Dec 15, 2013
If we have to arrange large array structure, and we should also have to set a field which is the 'index' of elements in the structure array as:
typedef struct {
int index;
char [MENU_ELEMENTS_CHAR_MAX];
int value;
boolean enable;
} stc_MenuEntry;
const stc_MenuEntry GlobMenu[] =
[Code] ....
Suppose we have a lot of row like those written before: also many structured array , and we should mantain: inserting and deleting elements, without having to worry about index error insertion, what kind of preprocess should we choose to best perform the automatic field writing? Obviously we could set properly any array field as:
{
{START_INDEX, "menu_voice01",100, TRUE },
{NEXT_INDEX, "menu_voice02",100, TRUE },
{NEXT_INDEX, "menu_voice03",100, TRUE }
......
.....
};
Just to make the task easier, maybe to allow a 'program filter' to find and subtitute the field as required.
We should also put theese menu variable in RAM, and perform the field init, setting the index at run time, but if we want to save RAM (const attribute chosen) we must find a solution.
I thought about UNIX/LINUX OS filter like sed and awk which would maybe perform the task, before giving the source file to the building process, but I'm working on Windows environment and I don't know the appropriate tool to do this kind of work.
View 2 Replies
ADVERTISEMENT
Sep 11, 2014
I'm trying to write a simple program that extract the FAT information from a FAT32 virtual Hard Disk.I have the following structures regarding the FAT format:
Code:
//BOOT RECORD
typedef struct NF_BOOT_RECORD
{
unsigned char BS_jumpBoot[3]; //EB 58 90 = JUMP 58 NOP (Jumps to boot code). Also E9 is acceptable.
unsigned char BS_OEMName[8]; //Either MSWIN4.1 or mkdosfs
unsigned short BS_BytesPerSec; //Little endian. The size of a sector. 128,256,512,1024...
unsigned char BS_SecPerClus; //The number of sectors per cluster (1 CLUSTER = BPS*SPC BYTES)
unsigned short BS_RsvdSecCnt; //The boot sectors (this) are included. That makes at least 1.
}
[code]...
Everything seems to work fine. Mostly. The only problem, is that the program gives me the following output:BS_NumFATs shouldn't be 0. In fact, I've checked inside the structure memory, and the information seems correct. BS_NumFATs is 0x02, not 0x00 (It's the byte at offset 0x10, starting at 0x00).
I've checked the order of the structure fields, and their types, comparing them to the FAT specification given by Microsoft (File fatgen103.pdf), and it seems fine, unless I'm missing something. So I don't know why it gives 0 instead of 2, if I'm missing something.It's a Win32 program compiled with GCC version 4.4.0
View 3 Replies
View Related
Apr 12, 2015
So I have this class
class DataBase
{
// Change the connection path here to your own version of the database
public SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)v11.0;AttachDbFilename=|DataDirectory|UberDatabase.mdf;Integrated Security=True;");
public DataBase()
{
}
}
And in the same namespace as this class I have a form that calls it like so:
DataBase dBase = new DataBase();
SqlCommand trythis = new SqlCommand("Register", dBase.con);
However, I'm getting the field initializer error on dBase.con. I'm not sure why, but when I call the database from another file (program.cs) it works fine this way.
View 8 Replies
View Related
Dec 9, 2014
I am trying to execute a very simple piece of code. But I am unable to find how the value of T[i][j] is changing all of a sudden. CODE:-
insert Code:
void initialize(float** &T,int NP,int D,int low,int high) {
int i = 0,j = 0;
T = (float **)malloc(NP*sizeof(float));
for(i = 0;i<NP;i++)
[code].......
View 2 Replies
View Related
Feb 13, 2015
I am wondering if integers and unsigned integers automatically assigned to zero (0) upon declaration like so:
bool randomFunction() {
int i;
if (i == 0) {
return true; //Will most modern compilers return true here?
} else {
return false;
}
}
I am just curious as I have always initialized my ints/unsigned ints variables. Would save me a lot of typing if I didn't have to do this all of the time.
I know that floats and doubles you still have to initialize.
View 4 Replies
View Related
Sep 17, 2012
Im doing a little game, casting dices etc. The problem is that the program will ask for player 1 then if i enter a name and enter it will ask for player two and so going on until i just press enter with a empty field and then continue the game.
The problem is i don't have any clue what code bits to start studying and how i shall lay it up, feels like i need a new string declaration automatically for each name.
View 5 Replies
View Related
Mar 8, 2013
I have a triple hierarchy class:
template<class T> class Singleton;
class Base;
class Sub : public Base, public Singleton<Sub>;
I' using underlying auto pointers, that's why Singleton is a template class and Sub passes itself as a template parameter. I'm developing Singleton and Base and a public API allows anyone to add their own sub classes. I actually want a real triple hierarchy like this:
template<class T> class Singleton;
class Base : public Singleton<Base>;
class Sub : public Base;
So that external developers don't have to worry about templates and complexity. The problem with this is that my implementation in Singleton will now call the constructor of Base whenever I create an instance of Sub (since the template parameter is Base).I was wondering if this could be done by pre-processor macros:
template<class T> class Singleton;
class Base : public Singleton<__CLASS_NAME__>;
class Sub : public Base;
Where __CLASS_NAME__ is the class name that will be replaced by the pre-processor. Theoretically this should be possible, since the __PRETTY_ FUNCTION__ macro actually returns the class name. The problem is that one cannot do string-manipulation to remove the function name from __PRETTY_FUNCTION__.
how I can accomplish this so that the Sub class is not aware of inheriting from a Singleton<template> class?
View 9 Replies
View Related
May 7, 2013
When using wxWidgets, i am tempted to deallocate memory using delete in the destructor, but my program crashes on closing. I try to do something like this:
class mainwnd:public wxFrame{
public:
mainwnd():wxFrame(NULL,wxID_ANY,wxT("test")){
menubar=new wxMenuBar;
[Code] .....
tell me why? and is it done automatically?
View 3 Replies
View Related
Mar 26, 2012
How do I tell c++ to move the mouse in place x?
for example, I run a c++ program and the mouse moves to the top left corner of my screen.
How do I go about doing something like that?
View 2 Replies
View Related
Aug 27, 2013
I am trying to run a programme implementing a function with structures in c... which is:
#include<stdio.h>
#include<conio.h>
struct store {
char name[20];
float price;
int quantity;
[Code] .....
View 1 Replies
View Related
Apr 13, 2014
I'm using Visual C++ 2010 and SFML game library. I want to know how to move an object from right to left automatically and back left to right??
View 2 Replies
View Related
May 18, 2013
Say I have an object and 10 pointers to it in several other objects of varying class types. if the object gets deleted, those pointers have to be set to null. normally I would interconnect the object's class with the classes which have pointers to it so that it can notify them it is being deleted, and they can set their pointers to null. but this also has the burden that the classes must also notify the object when THEY are deleted since the object will need a pointer to them as well. That way the object doesn't call dereference a dangling pointer when it destructs and attempts to notify the others.
Auto pointers and shared pointers are not what I'm looking for - auto pointers delete their object when they destruct, and shared pointers do the same when no more shared pointers are pointing to it. What I'm looking for is a slick method for setting all pointers to an object to null when the object destructs.
View 1 Replies
View Related
Nov 15, 2013
I am new to programming all together but i have been writing a program in c++ and im coming up against an issue with my array.
#include<iostream>
#include<iomanip>
#include<string>
using namespace
int main () {
int a ;
int b ;
char answer ('Y') ;
[Code] ....
I am trying to get the program to increase say year one by 1 when the condition is met i have tried
if ( a >= 70 && a <= 100 && b == 1)
{grade [0][0] = 0 + 1;}
and
for (grade[0][0] = 0 ; a >= 70 && a <= 100 && b == 1 ; grade [0][0]++)
{grade [0][0]= 0 + 1 ;}
Now all that i want is that the array will take the information from int a and int b and then add 1 to the appropriate part of the array . I have tried putting it in deferent places but its not working for ether. the program will run but it will not add to the array.
View 13 Replies
View Related
Jul 7, 2014
I recently noticed that I don't need to include the required header files inside header files that I have written myself. As as example, GLuint is defined using typedef unsigned int GLuint; inside glew.h. If I create a sample.hpp header file and mention GLuint without including glew.h, the compiler automatically works out that there is a typedef in glew.h. However, if I mention GLuint in a source file the compiler starts to complain. I have seen this happen in VS 2010 and 2013.
Edit: I should have mentioned that I am not including any other header files so I'm not indirectly including glew.h
In case you need to look at the code:
#ifndef CP_SHADER_LOADER_H
#define CP_SHADER_LOADER_H
namespace cp {
[Code].....
View 6 Replies
View Related
Jul 8, 2013
In my program, I create controls by deriving base objects of them I've made. These controls are then are attached within the OnCreate() function via a method I've created. For example:
Code:
class tChat: public TextBox {
public:
void OnKeyDown(UINT &KeyCode) {
if (KeyCode == VK_RETURN) {
MessageBox(NULL, "Pressed enter!", NULL, 0);
[Code] ....
The use of AddControl() feels quite redundant and is only their to parse a pointer to txtChat's Parent. I'm trying to see if it's possible to remove this line and automatically associate txtChat to fMain.
Currently my hierarchy looks like:
[User's derived Form] -> [MDIForm or Form] -> [FormBase] -> [Object]
[User's derived Control] -> [TextBox, etc..] -> [Control] -> [Object]
The user can then derive the Form and Controls and use their virtual OnEVENT functions to handle all the messages they expose.
So far my first concept is using the order-of-creation based on base-class constructor's being fired to determine which object is associated with what.
If I create a copy of a class (i.e. a Form-derived object), first the Form's constructor is fired, and then the constructor's of any class-based member-variables are fired. Is this a safe assumption? I imagine the only time this could be affected is by another thread creating the object of a Form or Control derivative?
If this assumption is true, I could save the 'this' pointer from the FormBase constructor, and then associate it with each Control via the base Control class' constructor? Then to ensure thread-safety, I could map the current FormBase pointer to the local thread id to ensure no conflict if multiply threads are creating forms at the same time?
I've created some mock-up code before trying to implement this into my main code. The following keeps track of the current Form being created by using a ThreadId-based map. When a control is created it gets the FormBase pointer based of it's ThreadId calling. The control then calls an Attach() function of it's parent Form using the pointer it just got, and parses a pointer to the control. The Form then adds the control's pointer to a list. When the Form eventually parses WM_CREATE, it automatically pulls the controls from the list and fires their virtual Create() functions to build them.
Mock-up:
Code:
#include <Windows.h>
#include <string>
#include <map>
#include <list>
class FormBase;// Forward declaration
class FormMap;// Forward declaration
class Object {};// Base Object
[Code] ....
Is this plausible to use? I imagine C++ does not have many "guarantees" about how it creates objects and when. But I thought it would be safe that it would never create member-variables before the class of them is first created?
View 2 Replies
View Related
Dec 7, 2014
Why doesn't this compile?
struct hi(){
void other();
}histructure;
void hi::other(){
std::cout << "Hi!" << std::endl;
[Code] ....
Makes no sense the structure is written before the structure member function is called so why is there compile errors ??...
View 3 Replies
View Related
May 8, 2014
Given an array of angles A = [0 30 60 90 120 150 180 210 240 270 300 330 360]
Write a program that will generate the data set of angles automatically and provide three columns; sin(angle), cos(angle), tan(angle). Make this program as compact and readable as possible.
View 2 Replies
View Related
Sep 6, 2013
#include<windows.h>
#include<conio.h>
void gotoxy(int x,int y);
void gets_ex(char*, int max_chars);
int main(int argc, char *argv[]) {
char urname[16], surname[16], fullname[32];
start:
system("COLOR 1c");
[Code]...
View 8 Replies
View Related
Jun 10, 2014
#include<iostream>
#include<conio.h>
#include<fstream>
#include<windows.h>
using namespace std;
int main(){
string ptr,a;
string b="E:project";
[Code] ....
View 4 Replies
View Related
Oct 7, 2014
Is it possible to assign a value to structure member inside the structure.like.....
struct control{
char tbi:2 =0;
char res:1 =0;
};
View 6 Replies
View Related
Oct 2, 2014
Ok I'm on a Windows machine and I'm writing a simple tool to dump and touch ttf files. It's almost done except that the command line parser is giving nightmares. how do I stop the shell from automatically converting wildcards in arguments to directory listings? (I first flatten all arguments to a single string before parsing)
View 7 Replies
View Related
Dec 26, 2013
So far I have managed to write the code for a simple game (resembling to "Pacman") :P. Now what I want is to move the smiley in the upper left-hand corner of the map "automatically" when the program runs and also want it to change it's direction to up or down when it touches the wall.
Also the screen is flickering when the program runs (due to re-printing the whole array?). I want to stop this flicker. Somebody suggested to use 'gotoxy' function.
Here's my code :
#include <iostream>
#include <conio.h>
#include <stdlib.h>
using namespace std;
void display (char array [10][25] , int row , int column) {
[Code] .....
View 8 Replies
View Related
Mar 17, 2013
how I can create a structure that pointing to another different structure. And also passing structure to function.
View 3 Replies
View Related
Feb 16, 2013
I have a file which has records with 2 fields--one int and one float..what is the best way to sort it?
The sorting has to be based on the int field(the first field) (each time the program runs the file might end up with some hundreds of records).
View 13 Replies
View Related
Apr 21, 2014
I wrote a script that generates n random pixel positions and draws them to the screen. Works well. Now i tried to rotate them. Rotating does work too. But it does not work as i planned it.
paramters 'angle' and 'timestep' work somehow, but not as they should do. the function 'move' is supposed to rotate the pixelfield 'angle' degrees in a given direction, addicted to the 'timestep' parameter. 'timestep' is needed time for drawing in one single game loop.
angle_step = timestep * angle
// x
ppdPoint[i]->x =
pRotationPoint->x + cos(angel_step) * (ppdPoint[i]->x - pRotationPoint->x) - sin(angel_step) * (ppdPoint[i]->y - pRotationPoint->y);
// y
ppdPoint[i]->y =
pRotationPoint->y + sin(angel_step) * (ppdPoint[i]->x - pRotationPoint->x) + cos(angel_step) * (ppdPoint[i]->y - pRotationPoint->y);
rotation point is the middle of the screen. when i set angle to 10 it should rotate 10 degrees / second. Instead it's rotating very very fast and all stars are moving nearer to the center of the screen, so after x rounds there is just 1 pixel left in the middle of the screen. there is a kind of gravition.I'm working with SDL2. What I did find out:
FPS is <= 60, 'cause of the 'SDL_RENDERER_PRESENTVSYNC' flag. When i skip that flag, for any reason the 'gravition' would take more time. FPS is <= 1400 then, 'though i got a natural game loop (i hope):
while(pBuild->getExecuteFlag())
{
pBuild->draw();
pBuild->update(time_dif, pTimeWindow->TimeStampB);
time_dif = (pTimeWindow->TimeStampB - pTimeWindow->TimeStampA);
time_dif *= 0.001;
pTimeWindow->TimeStampA = pTimeWindow->TimeStampB;
pTimeWindow->TimeStampB = SDL_GetTicks();
pBuild->count_fps(pTimeWindow->TimeStampB);
}
So maybe (timestep * angle) isn't the right way?
View 13 Replies
View Related
Aug 8, 2014
I need writing a program in c++ that will get the input of 50 different users for the following the fields (surname, other names, sex, status, date of birth) and after entering the data for these 50 users, it will then output only the list of all FEMALE users who were registered...
#include <iostream>
#include <string>
using namespace std;
int main () {
string surname, other_names1, other_names2, status, sex, dob;
[Code] ....
I don't really know what to do next - all my attempts have not really given me the result I want.
View 19 Replies
View Related