edbrowse-dev - development list for edbrowse
 help / color / mirror / Atom feed
* [Edbrowse-dev] Mix
@ 2013-12-23 15:36 Karl Dahlke
  2013-12-24  8:52 ` Adam Thompson
  0 siblings, 1 reply; 6+ messages in thread
From: Karl Dahlke @ 2013-12-23 15:36 UTC (permalink / raw)
  To: Edbrowse-dev

I'm reading through the online tutorial
http://www.cplusplus.com/doc/tutorial
It's interesting, I guess, though not as interesting as Shogun.

It is reassuring, and unsettling, that you can mix C and C++.
Here is a little program that is a mix of both, yet it compiles and runs fine.

--------------------------------------------------
#include <iostream>
#include <string>
#include <stdio.h>

using namespace std;

void duplicate( int& a, int& b)
{
a *= 2;
b *= 2;
}

int main()
{
string s;
getline(cin, s);
cout << s << endl;
int x = 6, y(7);
duplicate(x, y);
printf("%d,%d\n", x, y);
}
--------------------------------------------------

The point for us is that jsdom.c and jsdom.cpp
might not have to be very different at all,
since most of the c should carry along.
Maybe we can get lucky and just change the calls to the js engine.

Karl Dahlke

^ permalink raw reply	[flat|nested] 6+ messages in thread
* [Edbrowse-dev] Mix
@ 2013-12-24  9:30 Karl Dahlke
  2013-12-24 13:09 ` Chris Brannon
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Karl Dahlke @ 2013-12-24  9:30 UTC (permalink / raw)
  To: Edbrowse-dev

Adam writes:

> Slightly pedantic note about this, in c++ you *should* really use
> #include <cstdio>
> Rather than
> #include <stdio.h>

But that's my point, isn't it?
We don't have to change everything over right away for it to work.
Maybe we should, someday, but we don't have to, not right away.
The preexisting code works.

> You could also use
> cin >> s;
> Instead of
> getline(cin, s);

This is not true.
If someone types in the line

hello world

The first construct will capture only hello, a string separated bye whitespace,
whereas getline() captures the entire line.
The tutorial recommends using getline,
because you know exactly what you are getting, the line as it was typed.
It doesn't vary with whitespace.
Then you can analyze it and take action accordingly.
So when I do convert edbrowse to c++,
I can replace fgets with getline.
Still there are advantages.
I don't have to have a fixed buffer of a fixed size,
or worry about what happens if the user types in a line longer than that buffer,
or clip crlf off of the entered line;
c++ does all that for us.
So there are still some big advantages to c++, and yet,
you can't really go all the way over to the shorthand that your
professor put up on the board and showed you how cool it is.

Yes I will globally replace bool with eb_bool.
Obviously I thought the bool datatype was very useful,
but I hadn't anticipated the collision with bool in c++.
Thanks for spotting that one.
I'll make that change and push in the next day or so.

Karl Dahlke

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-12-24 15:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-23 15:36 [Edbrowse-dev] Mix Karl Dahlke
2013-12-24  8:52 ` Adam Thompson
2013-12-24  9:30 Karl Dahlke
2013-12-24 13:09 ` Chris Brannon
2013-12-24 14:48 ` Chris Brannon
2013-12-24 15:30 ` Adam Thompson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).