|
You need to print each byte independently, after casting them to int , since the char values are unprintable. Something like:
cout << hex << (int)buf[0] << endl;
Use a loop to print more than one value.
|
|
|
|
|
Thanks, but...
I know how to get buf values, what I wanted to verify is that the buf values are actually passed to the struct.
I am having issues verifying that the struct has all of the necessary data.
Some are "straight" values, most via pointers.
BTW
When I use "modifier" hex , not sure I am using correct term as always, in cout << hex << (int)buf[0] << endl;,
then following usage WITHOUT such modifier will continue to print the data in hex
cout << int)buf[0] << endl;
Nice but it can get out of control.
|
|
|
|
|
Vaclav_ wrote: I am having issues verifying that the struct has all of the necessary data. You need to be specific, we cannot guess what these issues may be. And, TBH, my previous reply was also based on a bit of guesswork.
See <iomanip> functions[^] for details on using the hex manipulator.
|
|
|
|
|
I just like <b>to see the value</b> passed to struct pointer.
I can deal with what the functio0n does with it myself.
Perhaps it is all working correctly and my problems are elsewhere.
|
|
|
|
|
I am trying to wrap a c++ class for c. The function uses pass by reference.
Example
Test::funcref(int & h,BSTR & b)
void wrap_funcref(wrap_t *m, int h, BSTR)
{
Test *obj;
if (m == NULL)
return;
obj = static_cast<test *="">(m->obj);
obj->funcref(&h,&b);
}
Not sure if I need to change the c++ functions for *
|
|
|
|
|
obj = static_cast<Test *>(m->obj); obj->funcref(&h,&b); }
How do you define Test and wrap_t in your C code?
|
|
|
|
|
Hi richard thanks for the reply
obj->funcref(&h,&b); I know this wont work, don't know why I even typed it.
Any way here goes
file.cpp
//------------
// CONSTRUCTOR
//------------
Test::Test()
{
}
//-----------
// DESTRUCTOR
//-----------
Test::~Test()
{
}
HRESULT Test::funcref(int &h, BSTR &b )
{
HRESULT hr = S_OK
char cstr[200];
strcpy_s(cstr, "BLAHHHHH");
*b = A2BSTR(cstr);
return hr;
}
HRESULT Test::funcp(int i,int *y)
{
HRESULT hr = S_OK
*y = i +7;
return hr;
}
file.h
class Test
{
public:
Test();
virtual ~Test();
static HRESULT funcref( int &h,BSTR &b);
static HRESULT funcp(int i, int *y);
};
wrapit.cpp
struct wrapStruct
{
void *obj;
};
extern "C" __declspec(dllexport) wrap_t *wrap_create()
{
wrap_t *m;
Test*obj;
m = static_cast(malloc(sizeof(*m)));
obj= new Test();
m->obj = obj;
return t;
}
extern "C" __declspec(dllexport) void wrap_destroy(wrap_t *m)
{
if (m == NULL)
return;
delete static_cast(m->obj);
free(m);
}
extern "C" __declspec(dllexport) int wrap_funcp(wrapper_L2H *m,int i,int* y)
{
Test *obj;
if (m == NULL)
return false;
obj= static_cast(m->obj);
obj->funcp(i, y);
return true;
}
extern "C" wrapper_API void wrap_funcref(wrap_t *m, int* h,BSTR* b) //?
{
Test *obj;
if (m == NULL)
return false;
obj = static_cast(m->obj);
obj->funcref(h, b);
return true;
}
wrapit.h
#ifdef WRAPPER_EXPORTS
#define wrapper_API __declspec(dllexport)
#else
#define wrapper_API __declspec(dllimport)
#endif
struct wrapStruct;
typedef struct wrapStruct wrap_t
extern "C" wrapper_API wrap_t* wrap__create();
extern "C" wrapper_API void wrap__destroy(wrap_t *m);
extern "C" wrapper_API void wrap_funcref(wrap_t *m, int *h, BSTR* b); //?
extern "C" wrapper_API void wrap_funcp(wrap_t *m, int *y;
useit.c
#include "wrapit.h"
int z=0,uu=0,d=0,p=0;
BSTR uu,nn;
wrap_t *z = wrap_create();
wrap_funcref(&p,&nn); //not sure does not work
wrap_funcp(z,&uu); //works
wrap_destroy(z);
wrap_funcp works
wrap_funcref does not.
|
|
|
|
|
wrap_funcref(&p,&nn);
Where is p defined, and what is it? And where is the missing parameter that should be included per the declaration:
extern "C" wrapper_API void wrap_funcref(wrap_t *m, int *h, BSTR* b);
Some of this might also make a bit more sense if it was properly formatted between <pre lang="c++"></pre> tags, as my samples above. And the use of single letters for variable names is confusing.
|
|
|
|
|
Message Closed
-- modified 20-Jun-18 4:35am.
|
|
|
|
|
Lapmangfpt wrote: j = find(MyList[i].key.begin(), MyList[i].key.end(), tkey); // ERROR 1
// If not, add key and content
if (j == -1) // ERROR 2
You have to compare not wit -1, but with MyList[i].key.end()
|
|
|
|
|
Hi
I have gotten this error from time to time but have always gotten around by doing a build or rebuild
this time I even tried a clean nothing helps
Just wondering is the source stored in the PDB file
|
|
|
|
|
No but the debug information is. If the debugger cannot match the source line with the information in the PDB then it will put this message. Check that you do not have links to out of date files in the project anywhere. Alternatively make sure that there is not a file included somewhere that is not getting rebuilt.
|
|
|
|
|
Richard
I tried for the life of me to figure out why is wasn't being rebuilt I ended up using the option allow source to be different
thanks
|
|
|
|
|
I entered the unit testing world about a year ago and now my team and I start working with Linux.
Which mocking framework do you think is the best for Linux and why?
Thanks!
|
|
|
|
|
Welcome to codeproject.
I don't know.
Here's a Software Test joke instead of an answer:
A senior software tester and a entry level tester went into the company cafeteria and sat down. The senior employee removed a tuna sandwich from an old brown bag. The entry level tester promptly removed a ham sandwich from his man-purse.
Then a security guard noticed that these employees were breaking the rules and quickly came over to the table. "The company rules clearly state that you cannot bring your own lunch to the cafeteria!" the guard exclaimed.
The senior tester looked at the security guard, then shrugged his shoulders and exchanged sandwiches with the entry level tester. "I found a loophole in the company rule." he commented with his mouth full.
Maybe someone with more test experience will answer your question. You might get greater visibility by posting your question in the 'Quick Answers' section.
Best Wishes,
-David Delaune
|
|
|
|
|
All my code is C so unity, ceedling and cmock and it's irrelevent if it's linux, windows or embedded code. At the end of the day you are testing the code not the compiler implementation and optimizations of the code.
There is a pretty good background to it all at
Throwtheswitch.org[^]
There are also forums there if you need to ask questions.
In vino veritas
modified 29-Apr-18 23:18pm.
|
|
|
|
|
The company I work for started using Isolator++ for Linux and it seems to work so far pretty well
|
|
|
|
|
Nice! What are their mocking abilities?
|
|
|
|
|
you can mock and fake almost everything, any kind of
methods,
fields,
behaviors,
interfaces,
dependencies,
Instances, and more.
|
|
|
|
|
|
I have this code, which works on CodeBlocks, but when I try to run it in visual studio code, I get and error saying:
invalid operands to binary expression ('std::ostream' (aka 'basic_ostream<char, char_traits<char> >') and 'std::string' (aka 'basic_string<char, char_traits<char>, allocator<char> >'))
this is the code:
#include <iostream>
using namespace std;
class field{
public:
void Create_Area(int area){
string field[area][area];
for(int y = 0; y < area; y++){
for(int x = 0; x < area; x++){
field[y][x] = "+ ";
cout << field[y][x];
}
cout << endl;
}
}
};
What to do to fix this?
|
|
|
|
|
You cannot create an array on the stack using values that are not known at compile time. You need to change your code to:
void Create_Area(int area){
string field[][] = new string[area][area];
Also, I would suggest not using the class name for an array in that way. And the field variable is not available outside of the method that creates it.
|
|
|
|
|
I have changed that, but now how do I use it in this part?
Field[y][x] = "+ ";
cout << Field[y][x];
also, I don't really understand what you have done in the new string[area][area] part. Why use string instead of field?
|
|
|
|
|
Member 13802912 wrote: how do I use it in this part? Exactly the same as before.
Member 13802912 wrote: the new string[area][area] part. Why use string instead of field? Because you are trying to create an array of string objects. See new Operator (C++)[^].
|
|
|
|
|
fatal error: invalid operands to binary expression ('std::ostream' (aka 'basic_ostream<char>') and 'void')
this is the error i am getting.What should i do?
#include <iostream>
void Find(int arr[], int n, int sum)
{
unordered_set<int> s;
int temp;
for (int i = 0; i < n; i++)
{
temp = sum - arr[i];
if (s.find(temp) != s.end())
cout<< arr[i]<<"+"<< temp<<" ";
s.insert(arr[i]);
}
}
int main()
{
int arr[] = {1,2,3,4,5,6,6,5,56,7,11,13} ;
int n = sizeof(arr)/sizeof(arr[0]);
int sum = 12;
cout<<Find(arr,n,sum);
return 0;
}
|
|
|
|