what is zed doing here?
-
in this code?from where i need to understand that is deleting something? void Database_delete(struct Connection *conn, int id) { struct Address addr = {.id = id, .set = 0}; conn->db->rows[id] = addr;
As far as I know, this is not valid C++ code.
THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?! -- C++ FQA Lite
-
As far as I know, this is not valid C++ code.
THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?! -- C++ FQA Lite
this is C code!!!
-
in this code?from where i need to understand that is deleting something? void Database_delete(struct Connection *conn, int id) { struct Address addr = {.id = id, .set = 0}; conn->db->rows[id] = addr;
This[^] thread might help. It looks as though there are members of the Address struct one called set and it's getting initialized to 0, and another called id and it's getting initialized to the given integer id.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
-
This[^] thread might help. It looks as though there are members of the Address struct one called set and it's getting initialized to 0, and another called id and it's getting initialized to the given integer id.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
yes,but by the name of function says(database_delete),this function must delete something,and i don't know how it is deleting something
-
yes,but by the name of function says(database_delete),this function must delete something,and i don't know how it is deleting something
Just a guess, perhaps set is some kind of flag marking a record as inactive or something, as opposed to actually deleting a record. What a functions name is and what it actually does may be two different things. What's needed here I believe is some useful comments.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
-
Just a guess, perhaps set is some kind of flag marking a record as inactive or something, as opposed to actually deleting a record. What a functions name is and what it actually does may be two different things. What's needed here I believe is some useful comments.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
can i give you the entire code?maybe you will find my answer:)
-
in this code?from where i need to understand that is deleting something? void Database_delete(struct Connection *conn, int id) { struct Address addr = {.id = id, .set = 0}; conn->db->rows[id] = addr;
This ties into the code you posted below. Specifically, it's related to this method:
void Database_set(struct Connection *conn, int id, const char *name, const char *email)
{
struct Address *addr = &conn->db->rows[id];
if(addr->set) die("Already set, delete it first");addr->set = 1;
Basically, it looks like it's controlling whether or not you've already set the value in this row - so, to set a value here, you would call Database_delete first, which changes the value in id from 1 to 0, which means that the rest of Database_set can continue.
-
this is C code!!!
Yes, you are right. :-O
THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?! -- C++ FQA Lite
-
This ties into the code you posted below. Specifically, it's related to this method:
void Database_set(struct Connection *conn, int id, const char *name, const char *email)
{
struct Address *addr = &conn->db->rows[id];
if(addr->set) die("Already set, delete it first");addr->set = 1;
Basically, it looks like it's controlling whether or not you've already set the value in this row - so, to set a value here, you would call Database_delete first, which changes the value in id from 1 to 0, which means that the rest of Database_set can continue.
i understand now,thank you very much!
-
i understand now,thank you very much!
You're welcome. :-D