I have kept dummy as the data to be aligned.I will update hours, minutes, and seconds , but will not use dummy in any case. If I don't initialize 'dummy' does it make any errors ? Do I need to initialize hours, minutes, seconds as well before I use the structure ? If so is there any particular reason ?
Code: typedef struct _a { int id; } a; typedef struct _b { a my_a; my_a.id = 1; // error: expected specifier-qualifier-list before "my_a" } b;
I get error: expected specifier-qualifier-list before "my_a"
I must set the id for the kind of struct created inside the struct def because main() will be casting based on this id. Thats how I will know which structure b contains by it's id, there could be hundards of different structs with different values I will cast to the correct one and know it's members by it's id. How do I ?
This compiler on SYSTEM2 is happy. but second way does not look correct to me and compiler on system 1 complains about it. Which is the correct way to allocate memory?
If first one is correct then what should i look in for to avoid this error? Could this be an issue with compiler on SYSTEM2? If i use second method on SYSTEM2 code segfaults during malloc.
#include <stdio.h> #include <string.h> #include <stdlib.h> typedef struct mystruct1 { int a; int b;
If I have an integer variable like int a=9 then in the switch case If i write :
switch(a) { case 4+a: printf("hii"); }
Then why is this statement a compile-time error that variables cannot be used inside a case statement why does the compiler not subtitutes the values in place of the variables.
I have a question regarding composition and accessing members "deep" inside the composed structure. For example;
class A { private: int m_myInt; public: int myInt() const {return this->m_myInt;}; void myInt(int newInt) {this->m_myInt = newInt;};
[Code] ....
Now, from somwhere I have access to an object of type B where I want to update the A::m_myInt. How would you do this without "breaking" the whole purpose of private/public members?
B myB; myB.m_a.myInt(3); // Not allowed, and not desireable
I thought about implementing access through functons kind of like;
A & B::a() {return this->m_a;}; myB.a().myInt(3);
but I'm worried that this exposes my B::m_a-object too much. This would allow
myB.a() = A(); , right?
The following is a more desireable way of acces, but doesn't work for updating;
A const & B::a() {return this->m_a;}; myB.a().myInt(3); //Disallowed? myInt(int) is non-const.
What about this? Is this a good way of doing it?
class A { private: int m_myInt; public: int myInt() const {return this->m_myInt;};
[Code] ....
I guess it works? It would lead to a lot of data shuffling in case of larger sub-components.I would really like to do the following without exposing my components so much:
I'm about to begin work on an exercise that requires me to maintain a list of the variables inside a c source file. I'm trying to figure out how I'm going to pluck out the variable names from all the other noise. My first thought would be to count any word that isn't a keyword or other type of grammar syntax, such as parenthesis, brackets, semicolons, etc. right?
I have two classes, a Package class and a Person class. The Package class has two Person objects has member variables, a Sender and a Receiver. While overloading the << operator for the Package class so that it will make an output label from everything in the Package class. Here is my code...
class Package{ public: Person Sender; Person Reciever; int weight; double cost; friend ostream &operator<<(ostream &out, Package &pack);
[Code] .....
So my problem is on that last output line, I am unable to call Sender.getName()... etc. Is there a proper syntax so that I can access the members of the Person class while overloading the << operator for the Package class?
I have an array of structure that takes family information (name, age, and state) after it takes the users input it prints back all of the information that was input and then prints the family members that just live in Texas. After that I am trying to implement a function to average out the ages of all family members but I cant seem to get it right, whenever it gets to that part of the program it just outputs 0. I also tried adding an & sign prior to FAMILY[i].age and got an error of int from ptr with no cast.
Also I realize that the code only shows adding of the family members ages which is fine for now as I am concentrated on getting that to work in the first place.
I have a project for class where I have to create a structure and get user input for 3 structure variable arrays of 10. I am trying to figure out how I can use the same function to fill my different section of variables.
My Structure is an employee file of ID number, name, hours, payrate, and then gross pay. I have to create a function for each input function. I am confused on how to pass the structure variable so that I do not have to write 3 functions for each input. I would like to be able to get all the info for the first structure variable and then recall the same 5 functions for the next before moving along. I hope that I have been able to make this clear. Here is my code:
#include <iostream> #include <string> struct WeatherStats { double total_rainfall; int high_temp; int low_temp; int avg_temp;
[Code] ....
When I run this program I am able to input data for the three months but after inputting everything I am prompted with a run time error that states: Run time check failure#3: The variable 'temp' is being used without being initialized. I've underlined the statement that the compiler says is causing this error, yet there is no variable 'temp' in that statement.
Computer are very specific right? So in the problem statement total_yearly_temp = total_yearly_temp + temp.avg_temp; there is a variable called total_yearly_temp and one called temp.avg_temp, but there are none called temp. It can't be complaining about the WeatherStats variable I defined in the first line of the function called temp because I did the exact same thing in the previous function and there are no errors concerning that.
I keep getting the "Uninitialized Local Variable" error. But for my code it's says it's the variable 'pay' in my Manager Function. This is the only error that is popping up.
I've tried setting pay to 0 but when I do, I get a bunch of external errors. I've also tried assigning pay to WeeklySalary like this:
double pay = WeeklySalary;
//Calculating pay for a company
#include <iostream> #include <iomanip> using namespace std;
I am getting this message from Valgrind, As far as I can see what it points to is initialized. The memory it is referring to is freed in unload and I was not getting this error until after I added the check function. Valgrind was happy. Here is the code and the error message from Valgrind. I am trying to create a spell checker for an assignment for a online class I am taking. I just want to get this table working correctly before I add it to the rest of the program. The code seems to run fine but I have come to see that dos not mean much in C.
arortell@gentoo ~/Development/Projects/C_Projects/Data_Structures/HashTable $ valgrind --leak-check=full --track-origins=yes ./hashTable ==11360== Memcheck, a memory error detector ==11360== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al. ==11360== Using Valgrind-3.9.0 and LibVEX; rerun with -h for copyright info ==11360== Command: ./hashTable
I have airport class which should navigate planes, in its list to runways, with method move, theres a method prepare which changes the direction of flight to all planes, always before move is called, move just increments decrement x and y of plane in its list. But after calling two times in row airport->move(), I get screwed and I really dont know wheres the problem. Have I badly initiazed something? Iterator gets invalidated.
Valgrind Stacktrace Conditional jump or move depends on uninitialised value(s) ==26207== at 0x409601: plane::move() (in /home/xnovak11/Downloads/airport/main) ==26207== by 0x401FBD: airport::move() (in /home/xnovak11/Downloads/airport/main) ==26207== by 0x405FE1: io::start(std::istream&, std:stream&, std:stream&) (in /home/xnovak11/Downloads/airport/main)
This is the method where it fails. When I call it once, no problem, after second call I get instead of normal number in cout<<after move<< s1 i get like 8795456 ....
Code: fn(){ char c; if (runFirstTime){ #ifdef VC c=''; #else c='/'; #endif } ... // c is used in the rest of the function to construct some pathnames }
The problem is that the value of c is not defined the 2nd time the function is called (and subsequently). It somehow worked fine under CygWin compiled with gcc. So I didn't spot the flaw until it ran incorrectly under Windows complied with VC++ 2010. Then I found the error and changed the code to something like
So now it works correctly under Windows. Then I re-compiled the new code with gcc and to my surprise gcc produced exactly the same binary! How can this be? Does the gcc compiler see my flaw and fix it for me somehow?
I discovered valgrind and started using it for my c code. But I get following error message at almost every malloc position, :
==19505== 40 errors in context 10 of 12: ==19505== Use of uninitialised value of size 8 ==19505== at 0x10000416E: my_method (main.c:662) ==19505== by 0x10000159E: main (main.c:182) ==19505== Uninitialised value was created by a heap allocation ==19505== at 0x47F1: malloc (vg_replace_malloc.c:302) ==19505== by 0x100001C21: my_method (main.c:333) ==19505== by 0x10000159E: main (main.c:182)
and I really don't understand what it means. I already googled it but I didn't find out what is my mistake.SO here i just put one example:
Code:
int main(int argc, char** argv) {
//i declare my variables at this position Uint *used, *forbidden_jumps, *forbidden_jumpsV, *forbidden_jump;
/*now i want to allocate one of them, this is my line 333 from the error message*/
//a_num is set during the execution of the program, ALLOC(used, Uint, a_num); }
[code].....
Is there any support page for the output of valgrind? I found it on the homepage.
I'm trying to call a function via a function pointer, and this function pointer is inside a structure. The structure is being referenced via a structure pointer.
Code:
position = hash->(*funcHash)(idNmbr);
The function will return an int, which is what position is a type of. When I compile this code,
I get the error: error: expected identifier before ( token.
Is my syntax wrong? I'm not sure what would be throwing this error.
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.