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

* Re: [Edbrowse-dev] Mix
  2013-12-23 15:36 [Edbrowse-dev] Mix Karl Dahlke
@ 2013-12-24  8:52 ` Adam Thompson
  0 siblings, 0 replies; 6+ messages in thread
From: Adam Thompson @ 2013-12-24  8:52 UTC (permalink / raw)
  To: Karl Dahlke; +Cc: Edbrowse-dev

On Mon, Dec 23, 2013 at 10:36:25AM -0500, Karl Dahlke wrote:
> 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);
> }
> --------------------------------------------------

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

You could also use
cin >> s;
Instead of
getline(cin, s);
For added c++-ness (due to stream operators).

> 
> 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.

Hopefully, that and a few datatype changes.

Cheers,
Adam.

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

* Re: [Edbrowse-dev] Mix
  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
  2 siblings, 0 replies; 6+ messages in thread
From: Adam Thompson @ 2013-12-24 15:30 UTC (permalink / raw)
  To: Karl Dahlke; +Cc: Edbrowse-dev

On Tue, Dec 24, 2013 at 04:30:18AM -0500, Karl Dahlke wrote:
> 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.

Yep, I was just pointing it out, though it's certainly not required.

> 
> > You could also use
> > cin >> s;
> > Instead of
> > getline(cin, s);
> 
> This is not true.
> If someone types in the line

Good point, I forgot about the whitespace,
probably because I never use a plain cin >> to do input.

> 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.

Technically, if building with gcc (or against readline I *think*),
you can do this anyway.

> 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.

Nope, and personally I don't actually think this syntax is "cool" either.

> 
> 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.

Already made, also have replaced true and false with eb_true and eb_false.
Patches to be sent in a few minutes.

Cheers,
Adam.

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

* Re: [Edbrowse-dev] Mix
  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
  2 siblings, 0 replies; 6+ messages in thread
From: Chris Brannon @ 2013-12-24 14:48 UTC (permalink / raw)
  To: edbrowse-dev

Here's another replacement we will need.  "this" is a keyword in C++, so
we cannot use it as a name for function arguments in files that we
expect to compile with a C++ compiler.  Same goes for "new", but I don't
think there are any new's in jsdom.c or jsloc.c.  I'll find and fix uses
of this and new in these two files.

-- Chris

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

* Re: [Edbrowse-dev] Mix
  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
  2 siblings, 0 replies; 6+ messages in thread
From: Chris Brannon @ 2013-12-24 13:09 UTC (permalink / raw)
  To: edbrowse-dev

Karl Dahlke <eklhad@comcast.net> writes:

> Yes I will globally replace bool with eb_bool.
> I'll make that change and push in the next day or so.

I just did this, and everything is working after the rename.

-- Chris

^ 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).