C-Standards | C version of my Standards library | Game Engine library
kandi X-RAY | C-Standards Summary
kandi X-RAY | C-Standards Summary
C-Standards is the C version of my Standards library, originally written in Java.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of C-Standards
C-Standards Key Features
C-Standards Examples and Code Snippets
Community Discussions
Trending Discussions on C-Standards
QUESTION
Busy working on an old VB6 project, recently converted to VB.NET. The application was originally written in the 1990s, and all variable declarations (Dim dbVersion As Single
and so on) are crammed together at the top of methods, generally out-of-sight from where the variable is used.
The style of "declare all variables at the top of the function" was commonplace in the 90s, enforced in the C90 and earlier K&R versions of the C language. Some languages, such as Delphi, still use this declarative style. But the C99 and later C-standards, C++, C# and modern VB.NET allow for variables to be declared wherever they are used (IMO, a huge improvement).
My question is whether there was ever a time when this style was enforced in Visual Basic or VBA (or indeed VB.NET)?
...ANSWER
Answered 2021-Feb-17 at 22:58Suggested, taught in schools as a "best practice", but no, not enforced by the compiler - not to the extent that a declaration must appear before any executable statement in a procedure scope, no.
VB6/VBA code can declare locals anywhere within a procedure scope (the smallest possible scope in VB6/VBA); the catch is that Dim
(and Const
, also legal in local scope) statements aren't executable (you can't break on them), and I would guess the reason it was so warmly recommended to "just put them all at the top" is that local declarations must appear before the first use of a variable: having a block of declarations therefore ensures all local declarations are legal.
Caveat:
ReDim
statements are executable, and they act as aDim
declaration. It is perfectly legal to haveReDim someArray(1 To maxValue)
even ifsomeArray
wasn't previously declared, even withOption Explicit
specified.
But having a block of declarations at the top of a procedure isn't a modern best practice...
[...] are crammed together at the top of methods, generally out-of-sight from where the variable is used.
...and IMO this is exactly why.
VB.NET changed the rules of scoping a bit (you can now have an inner scope inside a procedure), but what it really did was to introduce a knowledge gap tight enough that VB6 devs wouldn't be too intimidated, but wide enough that the new language & framework could boast a new set of best practices - and the onboarding devs would just embrace them. New language, new ways: out with Hungarian Notation and walls of declarations at the top of procedure scopes - and just like that, the new recommendation was to declare variables where & as you need them, and to never prefix any identifier with a type abbreviation.
But much of the VBA crowd weren't devs, and didn't hop onto the .NET bandwagon, and essentially missed the memo with the updated best practices that could effectively apply in VBA/VB6 even though they were pushed for VB.NET. VBA/VB6 isn't necessarily stuck in 1997 though; the Rubberduck project (open-source, I manage it) aims to modernize the VBE, its tooling (static code analysis, refactorings, unit testing, etc.), and the coding practices around it.
QUESTION
I'm implementing SHA-3 following the official FIPS-202 document in Verilog. My state is represented by a one-dimensional register and I use a macro function to calculate the corresponding state index from the (x,y,z) coordinates in the document:
A[x, y, z] = S [W(5y + x) + z]
, W = 64
(p. 9)
I'm strictly following the guide on page 11 and came up with this:
...ANSWER
Answered 2020-Jul-20 at 18:10I think I found the solution. It is described in appendix of FIPS 202 B.1 (starting on page 26). A hint on this topic is given on page 25:
The convention for interpreting hexadecimal strings as bit strings for the inputs and outputs of the SHA-3 examples is different from the convention for other functions on the examples page. The conversion functions between hexadecimal strings and SHA-3 bit strings are specified in Sec. B.1. For byte-aligned messages, the hexadecimal forms of the padding for the SHA-3 functions are described in Sec. B.2.
There is a good explanation on how to circumvent this issue on cryptologie.net.
QUESTION
There is a rather silly problem with the number pi in C and C++. As far as I know M_PI
defined in math.h
is not required by any standard.
New C++ standards introduced a lot of complicated math in the standard library - hyperbolic functions, std::hermite
and std::cyl_bessel_i
, different random number generators and so on and so forth.
Did any of the 'new' standards bring in a constant for pi? If not - why? How does all this complicated math work without it?
I am aware of similar questions about pi in C++ (they are several years and standards old); I would like to know the current state of the problem.
I am also very interested in why oh why C++ still doesn't have a pi constant but has a lot of more complicated math.
UPD: I know that I can define pi myself as 4*atan(1) or acos(1) or double pi = 3.14. Sure. But why in 2018 do I still have to do it? How do standard math functions work without pi?
UPD2: According to this trip report for C++ Committee meeting in July 2019 in Cologne, proposal P0631 (math constants) was accepted into C++20. So it looks like at long last we will have number pi in the standard library!
...ANSWER
Answered 2020-Apr-27 at 10:17Up to C++20, no, none of the standards introduces the constant that would represent the number pi (π). You can approximate the number in your code:
QUESTION
The definition of spaceship operator is meant to have a strong definition of ordering, but does this affect the way your client code is written or just how to define your class comparison operators?
Since in other post are missing real world example I'm not fully understanding this part.
Other SO post about spaceship operator:
...ANSWER
Answered 2019-Jan-23 at 13:37<=>
allows the lazy way to also be the performant way. You don't change your client code.
Clients may see performance benefits when there was a using std::rel_ops
(or boost::ordered
etc).
An example
QUESTION
I am going through the Herb Sutter's
A journey: Toward more powerful and simpler C++ programming
Structure Binding section
In order to understand the concept .Best is to write a program I tried but getting some error
...Just want to try how to use structure binding on class with private data .Please ignore the below example.if any example you can provide
ANSWER
Answered 2017-Aug-26 at 20:10I think it's a typo/glitch in Herb Sutter's blog post: He should have made those members public, or provided getters for them, or made the std::get()
function a friend.
Also, it looks like Herb forgot to put "x" in the function signature...
Explanation of the get functionThe function you quote is similar to how std::get()
works for tuples. If I have
QUESTION
I'm writing a SHA256 implementation in Python, padding, parsing and message schedule seem to work fine, my problem lies in the hash computation. Currently I'm just trying to calculate the working variable 'a'. This is the value I get (In hex)
5d6aebe0
Expected Output, according to this:
5D6AEBCD
Here is my code:
Set the working variables to the constants specified in FIPS-180
...ANSWER
Answered 2019-Apr-25 at 20:13You need to add a lot more masking here to cut down overflowing bits. For example, your ROTR
:
QUESTION
From the early days of the transition between C++98 and C++11, I remember that there was some ABI-related trouble when linking together C++98 libraries and C++11 libraries. (See for example Mixing different C++ standards with GCC and the answers to that question.)
I have a special situation where part of my code needs to be compiled with a tool that only supports C++11, and another part uses C++14 features and can be compiled with a standard g++ that supports them. I can put each part of the code into its own library and link them. But I'm wondering: In general, are there any differences between C++11 and C++14 that would lead to (eg. ABI-related) problems here?
...ANSWER
Answered 2019-Mar-22 at 09:51The mixup for gcc was a stdc++ decision (not even gcc). They are indeed incompatible when you set the macro in a different state, but you can mix C++98 with C++11 with libstdc++ if you set it consistently. For instance, on RedHat, the default gcc compiler is old and doesn't support C++11, so the devtools with newer compiler have the macro set to old ABI by default so that they are always compatible.
So if you are consistent with your stdc++ library, no problem. No problem on libc++, VS...
QUESTION
According to Concepts TS, while an unconstrained deduced parameter yield new template type parameter each time, constrained deduced parameters yield only one template type parameter per constraint:
...ANSWER
Answered 2018-Nov-14 at 07:35People should really stop writing misleading trip reports with links to outdated papers, at least without a giant flashing neon pink disclaimer. The paper voted in is P1141R2, which will be publicly available in a few weeks. The approved design is roughly parts 1, 3, and 4 of P1141R1.
You get independent binding, i.e., two template parameters in your example:
An abbreviated function template is equivalent to a function template (17.6.5) whose template-parameter-list includes one invented type template-parameter for each occurrence of a placeholder type in the decl-specifier-seq of a parameter-declaration in the function’s parameter-type-list, in order of appearance.
This has been the expected direction since at least early this year.
QUESTION
Following my previous question, I'm really curious about this code -
...ANSWER
Answered 2018-Apr-19 at 12:25Yes, it's an aliasing violation to do this. So don't. There's no need to ever use sockaddr_storage
; it was a historical mistake. But there are a few safe ways to use it:
malloc(sizeof(struct sockaddr_storage))
. In this case, the pointed-to memory does not have an effective type until you store something to it.- As part of a union, explicitly accessing the member you want. But in this case just put the actual
sockaddr
types you want (in
andin6
and maybeun
) in the union rather thansockaddr_storage
.
Of course in modern programming you should never need to create objects of type struct sockaddr_*
at all. Simply use getaddrinfo
and getnameinfo
to translate addresses between string representations and sockaddr
objects, and treat the latter as completely opaque objects.
QUESTION
I'd like to pass templated functions around as if they were generic lambdas, however this does not work.
...ANSWER
Answered 2017-Jul-19 at 11:37Is there, in C++14/17/20, a very terse manner to enable the conversion from case 1 to case 2? I am even open to macro hacks.
Yes.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install C-Standards
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page