Click here to Skip to main content
15,399,197 members

Comments by den2k88 (Top 41 by date)

den2k88 1-Jun-22 9:36am View
Sadly no university ever teaches how to use a debugger. A part of this comes from the common usage of plain gcc, with gdb being a steaming pile of youknowwhat to use, and a part from the teacher being teachers and never having worked in real development.

Basically, I had to teach myself the use of a debugger well after graduation, when I started my first job - I used to debug image analysis algorithms with printfs... that's the sorry state of CS education nowadays.
den2k88 29-Oct-21 16:42pm View
1) yes, unless using some shortcut instructions all this bookkeeping has to be done manually: welcome to Assembly.
When a function begins the first thing it should do is to push the current values of ALL the registers it intends to modify. At the end of the function it has to restore them. This is important because the calling function might have been using them.
Also it depends on the calling convention, in some rare cases it the calling function that has to keep a copy of the registers it needs untouched but it's very very rare.

Also it is possible to repurpose some registers, to a degree. Might have some instructions not working properly though, consider that x86 is a CISC architecture, which means it has a LOT of instructions.

2) If you can find notes about a Computer Architecture courde based on x86 it would be the best: understanding the architecture is the first step in assembly. The Intel manuals for IA32 assembly are free and well done, keep in mind that they are product manuals therefore quite dry and fast on the basics and then there is a LONG reference manual for the gazillion instructions. They are still worth a reading, when I used them I already knew the architecture and glossed over that part, it might be very good.

As for MASM, its manual is the only source. It is one of the assemblers and it has its own macros and syntax.

Sorry for the curtness but I'm on vacation and writing from my smartphone, which is not particularly easy :D
den2k88 28-Oct-21 3:39am View
> About STRUCT being a macro, does this mean that the MASM32 Assembler converts that code into something that looks like the ebp snippet?

Yes, there should be the compilation option to show the expanded code before the 1:1 translation in machine code.

> And whenever you make an object in C(++) that is a struct/class, does the compiler simply treat every member of every struct as global variables?

Yes and no, usually global variables are placed in a separate segment of memory while local variables are always present only on the current stack. Also everything created with malloc() or new lives in a different area of memory, called heap, which is managed by the OS through low level APIs.

> Also, how does malloc() fit into this way of keeping track of things?

It uses an external memory segment which is "unlimited", the size and location of which is actually managed by the OS. There are OSes out there without heap, therefore without malloc and new - mostly for microcontrollers.

Does ebp always point at the end of the stack? Yes, in x86 and derived architectures EBP is a special purpose register which is also used by some CPU instructions. You may repurpose it but you have to restore its original content before returning from the function if you want the program to work - attacking EBP is (was) a good way to execute exploits, the dreaded stack overflow attack.

> Why 4 bytes before its start? Does that mean 4 bytes before the end of the stack? I thought eax was the primary/preferred register to put return values into.

It depends on the calling convention of the function, which defines where the function is expecting its arguments, where it stores its return value and who is responsible for cleaning up the function stack. The convention I know of are cdecl, stdcall and fastcall. The one you refer with eax as return register should be fastcall if I remember correctly.

Also I may have not been completely accurate on what the snippet does: watching more thoroughly it should be placing the argument of the printf 4 bytes before the current stack pointer, but IIRC the stack pointer grows "upwards", from high address to low address.

Consider that I'm not actively developing in x86 assembler since half a decade, so while I'm fairly sure the gist of my answer is correct I probably misplaced some explanation, especially since you're making more and more in-depth questions ;P
den2k88 27-Oct-21 3:17am View
They don't, assembler is a direct translation of machine code, it works at the machine level. At that level, memory is flat, there are only addresses. Every kind of logic or structure is added by the programmer, in Assembly, or by the language when using high level languages.

A variable is simply the content of a memory location, so is a member of a structure, the address of a method, everything. What do they mean in context is decided by the language constructs and the programmer's logic.

Down to the assembly there are no objects, no methods, no variables. Only a flat area of memory. Methods are functions, functions are lists of assembly instructions.

As for that snippet, it *should* (I am a bit rusty in MASM) access the stack (EBP register points at the end of the stack) 4 bytes before its start, which should be the location of the return value in function calls. It is not properly an array but raw pointer arithmetics in raw memory.
den2k88 8-Oct-21 6:24am View
You actually can, since once encrypted it becomes a standard DLL loadable with LoadModule. I know some company use this approach to have the same licensing / encription DLLs across all their products and only their products.
den2k88 26-Apr-21 5:02am View
You are using CRT functions, those use the system locale to print characters. Check if you are using the en_US locale instead of ja_JP.

Refer to your Operating System documentation for how to change your locale.
den2k88 15-Apr-21 9:16am View
There are reasons these are homeworks.
den2k88 13-Jan-21 3:56am View
This is a good angle I didn't think of, thank you!
den2k88 24-Nov-20 5:33am View
Actually all versions are downloadable for free and only the license tied to the account changes. In cases like this it is a reasonable assumption that the offered features depend on the subscription level.

VS is not banned on their site: I requested it and they delivered - but they themselves discovered they can't give me the license so I'm stuck with the 30 days trial.

Work is on their equipment but in my company's premises, but I'm working from home due to pandemic. Messy situation. I already spent 100$ to cable the house because I onbly had wifi and the suckers gave me a desktop PC without wi-fi. Since I was going to do it anyway (I wanted to move my net equipment in an area where the cat is allowed only under supervision) I didn't complain.

Well, I will embrace the suck. Thanks for the answer!
den2k88 24-Nov-20 4:54am View
Situation is complex: the environment is not on VS at all, it's on an IDE for a very well known embedded system.

That IDE sucks. It *is* workable but to find answers that with VS+VAX it takes me 30 seconds, it requires me half an hour with the right IDE.

So I have no pressing need, the customer is stingy and my company is trying to win them because they are OEM manifacturer for a large market we're not into.

I cant fsck up in any conceivable way.
den2k88 27-Feb-18 3:33am View
I upvoted and bookmarked it: I will probably need it in the near future and I would have stumbled upon the same obstacle :D
den2k88 10-Jan-17 11:26am View
Most of the times the definition needs no change whatsoever. By having them separated it's fairly easy to check if different versions of the same software share the same interface to the class (single software with hundreds of branches tailored to the customers, each branch possibly coming from different versions of the base software).

One thing is the interface, the other is the code. While Interfaces solve the problem they are actually a tool thought for other purposes (defining precisely what a class MUST DO to fulfill its end of the "contract") instead of giving a quick summary of what operation does the class do, which operations are accessible from the outside world and which data does it hold.
den2k88 10-Jan-17 11:21am View
Yes I knew them but they still keep together declaration and implementation. IMHO I'd end up hating them because instead of having a big book and an index (c and c++ way) I would end up with several booklets and no index whatsoever (partial classes).
den2k88 10-Jan-17 11:20am View
It's not MEF that I need (though I'll bookmark it for future needs, thanks), the whole reasoning is under OG solution. I just like to split what to expect from how it is implemented, it's a way to have better documented code (i.e I explain what a class does and the logic of it in the header, then the gory details and suggestion for a better code in the implementation. Less clutter).
den2k88 10-Jan-17 11:17am View
I normally use the header file to describe what to expect from a class, an index which me and my coworkers look and know instantly that this class has these methods, exposes those properties and defines these data types. If it's a derived class then it adds these methods and overrides these others. Then in the implementation file there are the gory details over which regions are useful and so on.

Partial classes are useful but still blocks comprising of both definition and implementation - there has been only a single instance in which I would have liked them in C++ though, splitting the implementation may lead to a bigger mess than before.

I guess I'll have to use interfaces for the needs I have but correct me if I am wrong, interfaces cannot declare nested types and data members, don't they?
den2k88 4-Sep-15 11:44am View
At work we are forced to use VB6 and my colleague did the very same thing: no way to make it work under Win7 64 bit.
den2k88 4-Sep-15 11:43am View
Please, please, please, sometimes a developer just don't have the choice. This answer bring no good to anyone...
den2k88 29-Jun-15 9:56am View
Reason for my vote of 4 \n This translates roughly to "check for nulls before using values" which is something any programmer not born in the JavaNullPointerException era does as a mantra. Still it is a useful "watch out, nulls can be returned even wheter you don't expect".
den2k88 23-Mar-15 6:16am View
My idea would be to loop asking 64 (or n) bytes and storing inside a buffer until either ReadFile returns FALSE or it reads less bytes than asked.

When you have to read an unknown amount of data it is the simplest way, and in many cases the only one.
den2k88 23-Mar-15 3:56am View
Oh, sorry, I didn't look deeply in the article: it means the same as *& but in a C++/CLI (for .NET) context.

^ means the same as * but for a managed reference, while ^% means the same as *&. More on wikipedia:
and MSDN of couse explains better (I have only a little experience with .NET).
den2k88 7-Jan-15 9:30am View
Reason for my vote of 3 \n It's hard to define the performance of one environmnet towards the other with a "simple" math computation, especially using the same algorithm, since it will be compiled somewhat similarly.

When we speak about C performance we take into account the possibilites of manual optimization, for example many algorithms may be rewritten to operate sequentially on the elements of a matrix in order to have only one cycle and one advancing pointer into the memory (Sobel algortihm for example), meaning less computation of indexes and non sequential accesses to memory.

Also the insertion of intrinsics and assembly code, plus the unsafe typecasts, function pointer calls, memory zeroing, allocation/deallocation of memory managed focussed on the single application...

Of course many of these techniquese aren't easy, nor secure or general - they all are tradeoff for performances, which in some environments are as important as functional requirements due to timing contraints on the provided output.

Concluding, I think this article is conceptually flawed, but the author for sure put a decent amount of work in it and did a decent job.
den2k88 20-Dec-14 8:48am View
Reason for my vote of 1 \n Plagiarism is well received on CP not.
den2k88 2-Dec-14 5:32am View
Then broaden your horizons, look even outside your country - I am Italian, I am used to look abroad ;) improve your spoken and written English, maybe think about studying abroad, for example in Italy there are Politecnico di Torino (Polytechnique University of Turin) and Politecnico di Milano (Polytechnique University of Milan) that regularly accept foreign students from any part of the world and provide grants.

This two universities give a high chance of finding jobs worldwide, and the English taught lessons aren't particularly demanding, being that many professors aren't native speakers as well.

By the way, it is quite normal having fears before finishing school, we all passed through that :)
den2k88 25-Nov-14 9:12am View
What error?
What is the expected result?

PS: next time don't write the title all in uppercase, it means shouting and it is rude.
den2k88 21-Nov-14 8:00am View
I'm sorry but can you tell us something more? The question is poorly worded - what do you mean with "How Do I Get The O/P In Single Digit"?
den2k88 20-Nov-14 15:48pm View
den2k88 20-Nov-14 5:10am View
Or, as the other users said above,

int WINAPI foo (LPSTR bla)

afer all WINAPI is just a define for __stdcall
den2k88 19-Nov-14 8:41am View
Can you expand? It's hard to understand what you're asking. Also please include the code in a preformatted block and please indent it correctly.
den2k88 19-Nov-14 3:52am View

This solution does exactly the same as putting the correct path in Additional Dependencies
den2k88 18-Nov-14 11:13am View
You're welcome!
den2k88 17-Nov-14 10:51am View
Nope, it means one *match*.

fscanf("%d %d") for example returns 2 if it sees 2 integers, 1 if there is only one, 0 if none. It is not tied to the number of characters!
den2k88 17-Nov-14 5:36am View
Aaaand the question would be? You posted this code extract in 5 questions with 5 different titles in the same number of different categories all of them this morning, which incidentally is the same day you subscribed. What are you trying to accomplish?
den2k88 17-Nov-14 5:15am View
It is not a question of programming language: there are math function parsers for every language invented. The choice of the language and IDE is a matter of your liking.

I would suggest using C, C++ or Java because VB6 is "dead" (almost, there are a number of companies including mine where it is still widely used for production code) but it has some limitations that mede sense 15 years ago (and many not even then). Also your acquired knowledge will be more useful. Still, the quickness of VB6 for scrap projects is unmatched IMHO.
den2k88 17-Nov-14 4:42am View
I comment myself: I though "function" as "subroutine that returns a value" not function as the mathematical element. Sorry!
den2k88 16-Nov-14 11:10am View
Ok, right I got it - that was pretty tricky indeed. Good solution!
den2k88 15-Nov-14 17:21pm View
What problem did you have with '&&'? It should work fine, also it's not safe to use ungetc to undo a fscanf.
den2k88 14-Nov-14 7:47am View
So you know it's shape. I'd say that either you try with the automatic learning project of OpenCV (I don't remember its name and I don't have OpenCV doc at hand nor free internet access, sorry for that) and a large number of samples - that would be the easy way since it requires little coding and headache or you start designing the logic to understand, based on the edges/contrasts/shape of the image if you are looking at a cooler o not.
That requires experience and a not trivial work to be done, but there are no other ways. Image processing is largely a non deterministic field.

EDIT: I found an answer on stackoverflow HERE

There are a little more accurate pointers than the ones I gave you before.
den2k88 7-Nov-14 6:31am View
This is a clever (meaning pretty harsh) exercise. I think I have drafted a solution (not tested) but since it is a homework it is better to find the REASONING behind.

I assume this is a basic programming course, so I will use only basic instructions and will not focus on efficiency - it might complicate things a lot.

First thing, you are working with a string and searching substrings. So for the first thing you should scan the string char by char with a for cycle (let's say we use the variable i as counter).

Second thing, you obviously need to look subsequent characters in the string, so you will need a nested cycle (let's use variable j) that starst from the current value of the outer loop and scans until the end of the string, comparing the i-th carachet with the j-th.

Third, you need to find substrings, so you might need another nested cycle (let's use k) that when i-th and j-th characters are the same starts looking if the characters at the positions i+k and j+k are the same, and counts the equal characters.

Then, if you have more than 1 character you found the substrings. I left out most of the logic pointing out only the basic block-building reasoning behind the problem, the same reasoning I followed to draft the solution.

Think on this and try to write it down, see what goes wrong and do some trials, them eventually report us where you're stuck or wether you've benn successful.

Hope to be of help,
den2k88 7-Nov-14 6:09am View
To make it work you should declare UniqueID in a .cpp (or .c) file, THEN refer to it with external in header and FINALLY including that header.

That is because whe you use the "extern" keyword you are substantially telling the compiler "look, somewhere in the code this symbol is defined so don't shoot an error right now and pass the job to the linker". But if that symbol is non-existant in any of the .obj files created by the compiler (and they depend entirely from the .c o .cpp files) it is the linker that issues the error.

Also, sorry for the dealy in the answer, I did not see your comment up until now.
den2k88 7-Nov-14 6:03am View
That's a homework, I'd bet on it.

Anyway, what do you mean with "symmetric substring"? In which context? How is it made?

When you ask question be more specific, try things and tell us where you're stuck. We could even help with the reasoning behind, but this is not a code-for-free site.
den2k88 5-Nov-14 3:22am View
What error does it give? Can you post a bit more of the surrounding code? Help us to help you!