Wednesday, May 20, 2020

Digest for comp.lang.c++@googlegroups.com - 6 updates in 2 topics

Thiago Adams <thiago.adams@gmail.com>: May 19 05:54PM -0700

On Tuesday, May 19, 2020 at 6:29:43 PM UTC-3, Keith Thompson wrote:
> for an existing type, not a new type. And I don't think there are
> any existing features that require a warning while disallowing a
> fatal error message.
 
Yes. I did not give details but I imagine that is something not
difficult to do compare with other new C++ features.
 
This static analysis tool have this feature.
 
https://www.gimpel.com/archive/strong.htm
 
and it also have some interesting comments about
the problem.
"Öö Tiib" <ootiib@hot.ee>: May 20 04:07PM -0700

On Monday, 18 May 2020 21:13:12 UTC+3, Mr Flibble wrote:
> Hi!
 
> When is C++ getting strong typedefs? I want strong typedefs!
 
There are various implementations available, even boost contains
a macro STRONG_TYPEDEF(a,b) AFAIK somewhere.
 
I have tried such but I did not observe significant benefits
from that. Same happened with enum class when used as kind of strong
typedef of underlying type. Idea feels god but reality does not
confirm it.
Barry Schwarz <schwarzb@delq.com>: May 19 06:24PM -0700

On Tue, 19 May 2020 15:21:23 -0700 (PDT), Ain? Paplauskait?
 
>Hello! I am making Hangman game with FLTK. I have a problem - I would like my function to compare each letter of the string word_4 to a certain character(entered from input widget). For example, my string word is
 
Please don't post the same message to multiple groups individually. If
your message needs to be in multiple groups, post a single message to
them by specifying the relevant groups.
 
--
Remove del for email
Paavo Helde <eesnimi@osa.pri.ee>: May 20 08:05AM +0300

20.05.2020 01:21 Ainė Paplauskaitė kirjutas:
> Hello! I am making Hangman game with FLTK. I have a problem - I would like my function to compare each letter of the string word_4 to a certain character(entered from input widget). For example, my string word is "sun" and I would like to compare the first letter with the entered letter(from input). So I need to compare 's' with string 's'.
> There is part of the code:
 
Your code is not complete, contains references to undefined types, does
not compile and does not have a main() function. So it's hard to tell
anything about this, especially given that your only complaint is "does
not work".
 
My first recommendation is to get rid of all dangerous C-style
anachronisms like void* parameters, C-style arrays, strcpy(). Also raw
pointers and reinterpret_cast should not be needed in such a simple
program. At first glance it looks like the C-style
array-decay-to-pointer misfeature is the immediate cause of your
problems, so why not get rid of it and to concentrate on learning one
language, not a bad mix of two.
 
 
"Öö Tiib" <ootiib@hot.ee>: May 19 10:17PM -0700

On Wednesday, 20 May 2020 01:21:33 UTC+3, Ainė Paplauskaitė wrote:
> Hello! I am making Hangman game with FLTK. I have a problem - I would like my function to compare each letter of the string word_4 to a certain character(entered from input widget). For example, my string word is "sun" and I would like to compare the first letter with the entered letter(from input). So I need to compare 's' with string 's'.
 
If you need to find position of char c in std::string s then why
do not you use string's member find() like s.find(c) ?
 
<https://en.cppreference.com/w/cpp/string/basic_string/find>
 
 
Jorgen Grahn <grahn+nntp@snipabacken.se>: May 20 05:58AM

On Wed, 2020-05-20, Paavo Helde wrote:
> not work".
 
> My first recommendation is to get rid of all dangerous C-style
> anachronisms like void* parameters,
 
I bet that comes from that FLTK library or framework he's using.
That's a valid use case for void* and reinterpret_cast.
 
> array-decay-to-pointer misfeature is the immediate cause of your
> problems, so why not get rid of it and to concentrate on learning one
> language, not a bad mix of two.
 
Yes; his code should leave the C world earlier; use std::vector or
std::array instead of C arrays of strings; use std::string instead of
C arrays of char.
 
>> string file_4;
>> string word_4;
>> };
 
I also don't understand what the _4 suffix is doing everywhere, and
why a dictionary contains 150 words, and one extra word.
 
Ah, I think I see now -- you sometimes play Hangman with four-letter
words. Shouldn't affect the naming of variables and members,
though.
 
Personally I would write classes for the core of the game and then
maybe write unit tests before I wrote the UI. Something like:
 
class Game {
public:
explicit Game(const string& answer);
// e.g. "_oo_ar"
void put(std::ostream&) const;
size_t size() const;
bool solved() const;
// total failed guesses
size_t mistakes() const;
 
// guess that the string is s; returns
// the number of errors in the guess/how much
// the hanged man should grow
size_t guess(const string& s);
};
 
/Jorgen
 
--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: