C :: Return Struct From DWORD (unsigned Int) Thread In Windows
Jul 12, 2013
In windows thread function not a void (as pthread in Linux).
Its type is DWORD(unsigned int) so my question is
How to return a struct (contain alot of different data types) from DWORD (unsigned int) thread in windows?
Code:
#include <windows.h>
#include <stdio.h>
#include <conio.h>
typedef struct {
char* name;
int id;
[Code] .......
View 12 Replies
ADVERTISEMENT
Mar 14, 2015
I'm having an issue with the following assignment:
Program is supposed to take in an unsigned number and afterwards return the 'n-th' member of the following recursive function:
f(1) = 1, f(2) = 2; f(3) = 3; f(n+3) = f(n+2) + f(n+1) + f(n), n>0;
When I worked with Fibonacci it was pretty easy since I just had to decrement the next member for each step. I used the following:
#include <stdio.h>
#include <stdlib.h>
#define MAX 100
int fib(int n) {
static int memorize[MAX] = {1,1};
if(memorize[n])
return memorize[n];
[Code] ....
My main problem is that I have no visual of the current function, as well as the fact that it takes the f(n+3) = f(n+2) + f(n+1) + f(n), whilist I've only got f(n) to begin with.
View 5 Replies
View Related
Dec 27, 2014
I've been trying to figure out how to get a return value back from a thread, and found all kinds of info on promises, futures, packaged_somethings, async, ....
Here's one of my failed attempts at promises/futures: [URL] ....
View 1 Replies
View Related
Jan 7, 2014
#define DWORD ?
How to I write this statement?
In my program, the DWORDs are treated as unsigned long, so that They are 64-bit "DWORDs" instead of 32-bit ones...
View 5 Replies
View Related
Dec 2, 2014
is it possible to define as template the following get functions.
class Config {
public:
enum { NO_ID = 999 };
struct ValueType {
bool a;
size_t b;
std::time_t c;
[code]....
View 6 Replies
View Related
Jul 20, 2014
I'm quite new to C and these days I have been playing around with a linked list. I managed to make a working version using pointers, ad only for the sake of learning I was trying to do the same thing just passing the "Object reference" Here is the method that apparently doesn't work..
Code:
struct Node addNode(struct Node head){
int value;
struct Node *n;
printf("Please enter the value
");
scanf("%d", &value);
[Code]...
when I return the function i have something like: head=addNode(head)
Unfortunately it does not work the way I aspect. I suppose that there is something I have left out..
Code:
like n->next=&head
// passing the address of the head at the next pointer of the struct
head =*n
//copy the values of the new node to the old head..
There must be something wrong with this line.. return head; What have I done wrong?
View 2 Replies
View Related
Apr 3, 2014
How can i write a function that will read an "unsigned integer" into a variable of type "unsigned short int"? i can not use cin >> inside the function.. so i am looking for atleast a hint!
View 16 Replies
View Related
Mar 17, 2013
i need to return a struct pointer dynamically allocated inside a function call void function() which is done using 'out parameters' in following code
struct my_struct {
int x;
} void my_function( my_struct** result ) {
my_struct* x = new my_struct{ 10 };
//...
*result = x;
}
Now i have a doubt, so if i want to print the return value from struct pointer, should i need to print it in the void function() or in the caller the function...
View 3 Replies
View Related
Sep 30, 2013
I am a newbie to C++ and VS ++. I have created a windows form application by dragging and dropping button, label..etc. i wish label text to be appeared as return value from a function. The function returns ' const char* '.how this returned string pointer can be used to display label text.?
View 9 Replies
View Related
Jul 30, 2014
I have a class which I wrote and one of its object is "SerialPort" .NET class. In my MainWindow I created instance of my class called "SerialPortComm", then I send through some functions of mine, commands to the Serial Port, and I receive answers through "DataReceived" event.
But when I trying to use Dispatcher.BeginInvoke to write my data I have received (successfully), nothing shows on the RichTextBox which I'm trying to write to.
What can caused that, and How I can make it works?
SerialPortComm.cs
public partial class SerialPortComm : UserControl {
public SerialPort mySerialPort = new SerialPort();
public void Open_Port(string comNumber, int baudRate) {
mySerialPort.PortName = comNumber;
mySerialPort.BaudRate = baudRate;
[Code] ....
View 7 Replies
View Related
Mar 30, 2014
unsigned char key[32];
139 unsigned char rfseed[32];
173 f = fopen("/dev/urandom","rb");
174 fread(key,1,32,f);
175 fread(rfseed,1,32,f);
I am having problems copying outputs of the above code into other unsigned char other[32]. I need to keep the output of dev/urandom for backup. But, when I try to assign the values by memcpy(other, key, 32), the values do not match. The same problem happens by assigning values index by index in a loop.
View 2 Replies
View Related
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
Mar 29, 2013
I'm writing some functions pertaining to binary trees. I've used recursion once before while learning quicksort but am still quite new and unfamiliar with it. And this is my first time touching a binary tree. So my question: In my addnode function, will the return root statement at the end ever return a value other than the value passed to the function?
Code:
#include <stdlib.h>
struct tnode
{
int data;
struct tnode * left;
struct tnode * right;
}
[code]....
View 4 Replies
View Related
Jan 11, 2015
From the page: [URL] ....
#include <iostream>
using namespace std;
int n;
int& test();
[Code] ....
Explanation
In program above, the return type of function test() is int&. Hence this function returns by reference. The return statement is return n; but unlike return by value. This statement doesn't return value of n, instead it returns variable n itself.
Then the variable n is assigned to the left side of code test() = 5; and value of n is displayed.
I don't quite understand the bold sentence. Shouldn't value of n and variable n be the same?
View 8 Replies
View Related
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
Mar 25, 2014
Is it really needed to specify 0 as an unsigned integer? I mean 0 is always 0 regardless it's signed or not, no? In the below example is the 0U really needed?
#include <stdio.h>
unsigned invert(unsigned x, int p, int n) {
return x ^ (~(~0U << n) << p);
}
int main(void) {
[Code]...
View 5 Replies
View Related
May 15, 2014
Consider this piece of code from the following website: [URL] .....
Code:
unsigned intx = 50;
x += (x << 2) + 1;
The website above says the following about the code:
Although this is a valid manipulation, the result of the shift depends on the underlying representation of the integer type and is consequently implementation-defined.
How exactly would a legal left shift operation on an unsigned integer result in implementation-defined behaviour?
View 5 Replies
View Related
Nov 10, 2014
I need to convert a string IP to an unsigned int (uint32), but however solutions I've found elsewhere have not worked (such as `atoi`).
When using `(uint32)"54.171.82.217 ";` : [URL] ....
When using `atoi("54.171.82.217");`: [URL] .....
How can I correctly convert the string version of the IP to the uint32 type?
View 1 Replies
View Related
Jan 26, 2014
I'm confused about the actual value of 8 bytes for unsigned integers.
The below code suggests the value is 13217906525252912201:
#include <stdio.h>
#include <inttypes.h>
typedef uint64_t byte_int_t;
int main(void){
byte_int_t t;
printf("%" PRIu64 "
", t);
}
./runprogram
13217906525252912201
However, when I use a calculator, I get a different value: 2^64= 1.8446744e+19
So I was wondering is this really 8 bytes? So I try below test and it produces 8, as expected:
#include <stdio.h>
#include <inttypes.h>
typedef uint64_t byte_int_t;
int main(void) {
byte_int_t t;
printf("%u
", sizeof(t));
return 0;
}
So why does C and my calculator provide two different results?
View 1 Replies
View Related
Apr 23, 2013
How do I print an unsigned char in c++? E.g.
unsigned char a[100] = "acdef";
wprintf(L"a is %u
", a);
wcout << "a is " << a << endl;
gives
a is 2880488
a is 002BF3E8
and not
a is acdef
a is acdef
??
what is the difference between unsigned char and char?
View 6 Replies
View Related
Aug 8, 2013
I have a double variable and depending on certain conditions I need to set certain bits of an unsigned short Variable. For example, if double var is odd I need to set the 15th bit of the unsigned short variable.
View 4 Replies
View Related
Jan 15, 2013
when you convert 1.7 to unsigned int, it becomes 1 or 2?
View 9 Replies
View Related
Oct 12, 2012
I've sometimes encountered unexpected runtime issues caused by unsigned values being decremented below zero.
Example 1: "unsigned_value += negative_integer_value;"
Example 2: "for( size_t i = size - 1; i >= 0; --i )"
My compiler doesn't provide any compile-time or run-time warnings.
As far as I know, it's not possible to overload operators of primitive data types to check if the unsigned value is decremented below zero.
Any clever strategy to trace such cases at debug runtime, without having to add asserts all over the code? It's important that it does not affect performance in release mode.
View 6 Replies
View Related
Jun 25, 2013
I have the following code below. I am getting a memory access violation when accessing cmd->query_string in the loop function. The loop() function is running in another thread. The cmd object appears to be destroyed after calling the send_command function. How do I create an object on the heap and access the query_string.
std::list<my_command_message_que*> my_command_que;
void loop(){
if(my_command_que.size() > 0){
my_command_message_que * cmd = my_command_que.front();
std::cout << cmd->query_string;
[Code] ....
View 2 Replies
View Related
May 9, 2013
I've been using threading for a while, that was no needing parameters. so I used for example the following line :
_beginthread(functionName, 0, (void*)10);
and it worked great...
but now I have a function that has an int parameter (int num), and I dont know how to transfer it using _beginthread...
View 2 Replies
View Related
Mar 3, 2013
I was working on a problem that was best solved with chaining threads together using a blocking thread-safe queue. Eg threads A and B pass data to each other using a queue ... a simple producer consumer design A -> B. This has two benefits: 1) being that there is a buffer between the two threads to cache for a slow consumer and 2) allows for better throughput when loads of data are high because the two can run in parallel. Most of the time the design works well under load. but I found when pushing data through the threads intermittently, i.e. once about 0.5 seconds it ran poorly, mostly from what seemed to be latency introduced during the OS waking up of the consumer thread B.
What i have come up with to solve this issue is what i call an .... Its a wrapper around a basic thread safe queue and adds one extra function called .... The idea here is that if you have a simple case (or perhaps a slightly more complicated case) of two threads in a prod cons design and you know the producer will create or received the data, process it, and then push onto the queue, why not give the consumer thread a heads up to let it know the data is about to arrive. In this case call .... In this way you can have the consumer thread in a polling state anticipating the arrival of data and avoid the time to schedule it back to a running state.
Anyway, i have some code below and I was looking to get some feedback. I have tested it somewhat and it does improve the responsiveness quite substantially.
View 7 Replies
View Related