|
i did but not really clear
|
|
|
|
|
And what is "not really clear"?
|
|
|
|
|
please could u tell me where you think is causing this
|
|
|
|
|
Something in your code is causing it. You wrote the code so you are the only person who knows what it is supposed to be doing. So start it in the debugger, single step through it and check every step to see if it is doing what you expect.
|
|
|
|
|
You are working with binary data not null-terminated character strings. Using strlen on that data is bound to give you all kind of nasty surprises.
Mircea
|
|
|
|
|
One thing I do notice is at the following line:
memcpy(exec, input, sizeof input);
If input is changed in any way after calling Reverse then sizeof may not reflect the modified size. Oh, and obviously you have converted it to a string, and not to a sequence of machine code instructions.
|
|
|
|
|
Hi I have the following vector type defined in a class The Class name CStorge
vector<tcbholder> tcbcollecter;
The tcbholder tpye is defined as such
struct tcbholder
{
char* tcb;
char programname[8];
vector <stdecs> strptr;
};
I would like to define an iterator in a thread for which I pass the obj or class pointer
with such
vector <tcbholder>::iterator tcbitrate = storage_ptr->tcbcollecter.begin();
this is the thread prototype type
UINT DialogStorageThread(CStorge *storage_ptr)
However I get he following complier error
76): error C2440: 'initializing': cannot convert from 'std::_Vector_iterator<std::_Vector_val<std::_Simple_types<_Ty>>>' to 'std::_Vector_iterator<std::_Vector_val<std::_Simple_types<_Ty>>>'
1> with
<pre> with
1> [
1> _Ty=CStorge::tcbholder
1> ]
1> and
1> [
1> _Ty=DialogStorageThread::tcbholder
1> ]
IS there any way I can do this ?
thanks
|
|
|
|
|
It looks your are trying to assign apples to oranges (while, unfortunately, fruit polymorphism is not in place ).
You should provide more code in order to get better help.
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
Hi all, I have the following in a bash script on my debian box, it works perfectly but I would like to configure a Makefile
I run this script from my project folder
g++ Source
|
|
|
|
|
You can use backslashes in the Makefile just the same. If you set all the includes into a macro it simplifies things a bit. Something like:
g++ Source/*.cpp -o callapi \
INCS = -I /home/pjk/vcpkg/packages/cpr_x64-linux/include/cpr \
-I /home/pjk/C++/CallCommandsAPI/Headers/ \
-I /home/pjk/vcpkg/packages/rapidjson_x64-linux/include/ \
-I /home/pjk/vcpkg/packages/cpr_x64-linux/include/
LIBS = -L /home/pjk/vcpkg/packages/cpr_x64-linux/lib/ \
-lcpr -lcurl -lpthread -lssl -lcrypto
SOURCES = <-- add the source names here - callapi.cpp etc.
TARGET: callapi
callapi: $(SOURCES)
g++ Source/*.cpp -o $@ $(INCS) $(LIBS)
You may need to add the Source directory name in front of all the dependency names in the SOURCES macro, in which case the last line could be changed to
g++ $(SOURCES) -o $@ $(INCS) $(LIBS)
This is untested but broadly follows a Makefile I use in Ubuntu.
|
|
|
|
|
Thanks Richard that will certainly get me started, what does -o $@ set the output file to ?
Life should not be a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming “Wow! What a Ride!" - Hunter S Thompson - RIP
|
|
|
|
|
The $@ is one of the predefined make macros and refers to the target of the build; which should be the output file callapi. I looked at the man page for make on Ubuntu but it seems incomplete. There is (certainly used to be) a section somewhere that gives all the details on Makefile structures.
|
|
|
|
|
With your help I've cobbled this together ( and it works ) thanks again
INCS = -I /home/pjk/C++/CallCommandsAPI/Headers/ \
-I /home/pjk/vcpkg/packages/rapidjson_x64-linux/include/ \
-I /home/pjk/vcpkg/packages/cpr_x64-linux/include/
LIBS = -L /home/pjk/vcpkg/packages/cpr_x64-linux/lib/ \
-lcpr -lcurl -lpthread -lssl -lcrypto
SOURCES = $(wildcard *.cpp */*.cpp)
TARGET: callapi
callapi: $(SOURCES)
g++ $(SOURCES) -o $@ $(INCS) $(LIBS)
clean:
rm callapi
Life should not be a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming “Wow! What a Ride!" - Hunter S Thompson - RIP
|
|
|
|
|
If you are interested in using the power of make to only compile modified sources that are newer than the target you should be able to do something like this
CPPFLAGS = -I /home/pjk/vcpkg/packages/cpr_x64-linux/include/cpr \
-I /home/pjk/C++/CallCommandsAPI/Headers/ \
-I /home/pjk/vcpkg/packages/rapidjson_x64-linux/include/ \
-I /home/pjk/vcpkg/packages/cpr_x64-linux/include/
LDFLAGS = -L /home/pjk/vcpkg/packages/cpr_x64-linux/lib/ \
-lcpr -lcurl -lpthread -lssl -lcrypto
SRCS = $(wildcard Source/*.cpp)
OBJS = $(SRCS:.cpp=.o)
ifdef DEBUG
CXXFLAGS += -ggdb
LDFLAGS += -ggdb
else
CXXFLAGS += -O2
LDFLAGS += -O2
endif
callapi: $(OBJS)
$(CXX) $(LDFLAGS) $^ -o $@
clean:
rm -f callapi $(OBJS)
I've added clean and debug options to help maintain your code. To make a debug version you do
make DEBUG=1 Note that $CPPFLAGS and $CXXFLAGS are standard make variables and will be expanded when trying to compile the individual object files, without us having to explicitly tell make to do so.
If you don't want the object files mixed in the source directory, look into using $(patsubst) [Text Functions (GNU make)](https://www.gnu.org/software/make/manual/html_node/Text-Functions.html#Text-Functions) and/or other make functions to manipulate targets. With some fancy footwork you could also get debug and production objects built at the same time, but I'll leave that as an exercise for the reader!
Keep Calm and Carry On
|
|
|
|
|
Thanks for this, one question, where is CXX defined ?
Life should not be a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming “Wow! What a Ride!" - Hunter S Thompson - RIP
|
|
|
|
|
CXX is defined in the bowels of make somewhere. It is the default variable for the C++ compiler, and is used in the rules for constructing default recipes. So for example, suppose you had an otherwise empty directory with only one file, hello.cpp, in it. Without needing to create a Makefile, you can build the hello executable just by saying "make hello". There's default rules for all kinds of things, C, Fortran, ranlib (.a) libraries, yacc, tex, and on and on. You can get a list of available recipes by saying "make -p", which for my version of make produces 1357 lines of output.
The CXX variable can be overridden by specifiying a shell variable of the same name at run time, so if for example you wanted to see what error messages clang++ spits out instead of g++ you can say
CXX=clang++ make target Similarly you have CXXFLAGS and CPPFLAGS which pass arguments to the C++ compiler and the CPreProcessor, respectively. So you could say
CXX=clang++ CPPFLAGS="-I /path/to/includs" CXXFLAGS="-O2 -Wall -Wextra" LDFLAGS="-L /path/to/lib" LDLIBS="-lmylib1 -lmylib2" make hello and make will apply the variables to the generated command line as expected, and produce:
clang++ -O2 -Wall -Wextra -I /path/to/includs -L /path/to/lib hello.cc -lmylib1 -lmylib2 -o hello
gnu make hack: You can rebuild everything from scratch, even if already compiled, without having to "make clean" by using the -B flag
It should also be noted that the Makefile I provided earlier uses GNU makeisms e.g. $(wildcard),$(patsubst) . If you find yourself on a BSD or other unix like system that does not have GNU tools installed, the given make file will fail. But the variable substitutions mentioned here will still work.
Keep Calm and Carry On
|
|
|
|
|
vector<vector<int>> mark[5]
Is this array of 2D vectors? How can I traverse or insert any element from user in this data structure?
|
|
|
|
|
Try breaking it down into its constituent parts:
mark is an array of 5 elements.
Each element is a vector.
And each element of the vector is also a vector.
And each element of the inner vectors is an integer.
As it stands though, the array is null, so you need to initialise each of its elements with a new vector. You then need to decide what actual information you want to store in the vectors.
|
|
|
|
|
I have a C++ function that takes as argument an iterator and needs to increment it without passing the end of the container. I can write it as:
variant A:
bool func (std::string::iterator& ptr, std::string& container)
{
if (ptr != container.end())
} and call it as:
func (s.begin(), s);
or I could write it as
variant B:
bool func (std::string::interator& ptr, std::string::const_iterator& limit)
{
if (ptr != limit)
} and call it as:
func (s.begin(), s.end());
(the example assumes the container is a string but that's not important)
Which one would you favor?
Mircea
|
|
|
|
|
If the function modified the contents of the container I would probably pass it the container reference, otherwise I would prefer the iterators (or even a std::span ).
|
|
|
|
|
Good points, thank you! However std::span is C++20 and I want to keep the code C++14.
Mircea
|
|
|
|
|
The second one: give to the function the strict necessary for its task.
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
Yep, my thoughts exactly. Thank you!
Mircea
|
|
|
|
|
"great minds..."
You are welcome.
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
I have a more or less strict rule i.e. to wit in particular to be specific namely things that act like pointers are passed via copy constructor not via reference since raw pointers are fundamental type objects so take up little space and a reference is a pointer anyway. I agree w/ the chap who suggested passing only what the function requires i.e. first, last iterators. Further at point of call the code is easier to understand its purpose as it passes only what the function requires also it just looks better and is easier to understand as fewer ideas/concepts are involved namely the one idea/concept "iterator" rather than the two ideas/concepts "iterator and container". Was there not a recent article in a recent CP newsletter discussing this very thing i.e. minimizing the number of ideas/concepts needed to understand any code?
|
|
|
|