Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
2.25/5 (4 votes)
See more:
I'm trying to continue a line of code and get seem to get the right syntax. Any help is appreciated. Thank you.

C++
if (( flags & 0x01 && flags & 0x10 ) && (ip_header->destination_ip == *addressValue)) / 
||(( flags & 0x02 && flags & 0x10 ) && (ip_header->destination_ip == *addressValue))/
||(( flags & 0x08 && flags & 0x10 ) && (ip_header->destination_ip == *addressValue))
			{
Posted

You don't need to use a continuation symbol in C++ to continue a line of code. C++ will ignore white space.
So leave out the extra symbols and it should work.

You do need the slash for continuing a string on multiple lines, that is likely what confused you.
 
Share this answer
 
v2
Comments
Member 7766180 21-Sep-11 17:18pm    
There was also a problem with the "(".....
if (( flags & 0x01 && flags & 0x10 ) && (ip_header->destination_ip == *addressValue)
|| ( flags & 0x02 && flags & 0x10 ) && (ip_header->destination_ip == *addressValue)
||( flags & 0x08 && flags & 0x10 ) && (ip_header->destination_ip == *addressValue))
Sergey Alexandrovich Kryukov 21-Sep-11 17:43pm    
A fix:


if (
(( (flags & 0x01) && (flags & 0x10) ) && (ip_header->destination_ip == *addressValue))
||
(( (flags & 0x02) && (flags & 0x10) ) && (ip_header->destination_ip == *addressValue))
||
(( (flags & 0x08) && (flags & 0x10) ) && (ip_header->destination_ip == *addressValue))
)


--SA
Member 7766180 21-Sep-11 18:07pm    
Thank you. I appreciate the help. Sincerely. 7766180
Sergey Alexandrovich Kryukov 21-Sep-11 19:54pm    
You're welcome. I'm trying to help -- sincerely. :-)
--SA
Stefan_Lang 22-Sep-11 7:37am    
Or:

if ((flags & 0x0B) && (flags & 0x10) && ip_header->destination == *addressValue)

Ok, not related to the problem, but I couldn't pass by that expression without optimizing it a bit ;-)

P.S.: seems like I couldn't even wait to read to the end of the page (solution 3), ^^
Does it makes sense to start this line, that is a question. :-)

I really think it does not make sense. If you ever took a labor of reading any C++ or C manual, you would know from the very beginning that there are no lines in C++ or C; the end of line in the file is treated the same way as blank space or, say, tab. Any language construct can take any number of lines; you only should not break literals, reserved words and identifiers (names). Just remove all those '/' at the end. (Where did you get them? They look familiar… From some other language? Who told you can or need to use them in C++ or C?)

I think it does not make sense because you apparently try to code without reading one of those manuals; and that makes no sense. It will really lead you nowhere. Do yourself a favor, read such manual, practice a bit on simple samples and come back. Honestly.

[EDIT]

Wait a second! I remember you! You already asked 113 questions! You try to write TCP packets and modify Windows registry! What's going on? You either try to troll all us or just waste your time and our time. Please, do yourself and all us a favor: stop all this, get yourself busy with something useful. Learn some programming for example — you're not doing it. Learn from scratch and with no rush, otherwise it leads you nowhere. At least think about it.

Best wishes,
—SA
 
Share this answer
 
v2
Comments
Member 7766180 21-Sep-11 17:06pm    
I did get the "/" from Googling.
Sergey Alexandrovich Kryukov 21-Sep-11 17:40pm    
Well, and what was the URL? :-)
--SA
Member 7766180 21-Sep-11 18:08pm    
I'm sorry, I cannot remember where....! :) I'm on several sites everyday.
Sergey Alexandrovich Kryukov 21-Sep-11 19:53pm    
Just forget it.
--SA
Legor 22-Sep-11 2:53am    
Is this really how you try to learn programming. You know like googling all kind of examples and try to glue them together? Why not start with a good tutorial. There are plenty of them out there.
redact the whole thing down to one check?

// or 0x10, 1, 2 & 8 to 0x1b
if (( flags & 0x1b ) && (ip_header->destination_ip == *addressValue))
{
}
 
Share this answer
 
Comments
Chuck O'Toole 22-Sep-11 1:03am    
Nope, all his include "flags & 0x10" so the only legal values are 0x11, 0x12, 0x18. Your change would allow invalid combos of 0x01, 0x02, 0x08, and 0x10.
barneyman 22-Sep-11 1:06am    
true!
Stefan_Lang 22-Sep-11 7:42am    
make it

if ((flags & 0x0B) && (flags & 0x10) && ip_header->destination == *addressValue)

The last two conditions are mandatory, the first assembles the 'or' conditions into one term like what you tried.
Member 7766180 22-Sep-11 13:45pm    
This looks like something I could apply over and over again... just a little confused on the first line though. If its rem out // how is it read? Thank you!
Stefan_Lang 23-Sep-11 3:46am    
The character sequence // introduces a one-line comment that will be ignored by the compiler. You can also use the character sequences /* and */ to indicate the start and end of a comment, respectively.

The solution above made an attempt to simplify the boolean expression in your if statement. To understand that transformation you must understand Boolean Logic.

This, as well as the above (about comments) is yet another thing that you cannot learn just from looking at code. I can just repeat what others have already pointed out: get yourself a good book or Tutorial!
As stated earlier, you don't need the continuation for code, however you would need it for strings.

Either way, the continuation character (to continue a line on the following line) is a \ instead of /. The \ is the escape character (as in \n, \r, etc), and in this case it indicates that the next character (end of line) is "special" - i.e. not included.

Hope that helps.
 
Share this answer
 
Comments
Member 7766180 22-Sep-11 13:43pm    
Thank you! I'm learning lot about end of lines! I appreciate it!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900