Unitial | đź–Ą My rc / configs / dotfiles | Command Line Interface library
kandi X-RAY | Unitial Summary
kandi X-RAY | Unitial Summary
A set of scripts and configs to initialize the environment for Unix-like OS,. Not fully tested but should work on FreeBSD, most of Linux distros and macOS. Feel free to fork, send pull request and feedback, but do not erase author info please. Questions and suggestions are welcome.
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 Unitial
Unitial Key Features
Unitial Examples and Code Snippets
Community Discussions
Trending Discussions on Unitial
QUESTION
I want to define a generic memoizing wrapper in Crystal. I have the following crystal code:
...ANSWER
Answered 2021-May-16 at 20:09You are using an unsafe feature "uninitialized
", which means, "keep whatever was there in memory previously" (in theory the value is random and possibly invalid, in practice you often end up with 0 anyway -- but it's still not guaranteed at all).
The short story about the uninitialized
feature is please never use it.
This behavior wouldn't surprise you if you wrote @val = 0
-- and that's kinda what you wrote.
You must define @val : T? = nil
-- to make it nilable (have this separate possible value of nil
, which is its own type - Nil
).
You may have thought that unitialized
brings nil
into the picture, but it definitely doesn't.
In response to your comment about also including nil
into possible values, here's a full solution, which, instead of Nil, uses a unique "sentinel" struct, that the user can never create.
QUESTION
I have a problem because my code does not work on the production server. When it comes to development environment, everything is fine. It looks like he doesn't read the classes. My ruby version is 2.6.6 and rails is set as 5.2.4.4.
lib/crm/api.rb
...ANSWER
Answered 2021-May-06 at 01:06You need to add /lib
to the eager load paths as well:
QUESTION
In C++ you can't include Header Files in each other because of recursion. So you have to make use of Predefined Classes right? So I want to get the value of num in C.hpp and print it out in B.hpp.
C Class gets initialized before B Class which is expected.
But when I'm trying to call A::instance->c it is NULL!
B Class with unitialized C Class
A.hpp
...ANSWER
Answered 2021-Apr-26 at 12:17C Class gets initialized before B Class which is expected.
No, it's not expected, the order of evaluation of function arguments is unspecified.
But even if that's the case as in your example output, you've created new C class object, and now you are trying to create B class object and during that, you are trying to access A::instance->c
which is not set yet.
You set c
for class A object in the start
function, but you are still evaluating its parameters during this calls and didn't reach the actual body of the function.
Thus, the c
in the class A is the default 0 as you set by C* c{ 0 };
.
QUESTION
I am trying to create an 'array of pointers' to a custom struct, dynamically allocating the memory since I am not sure of the size this array must have. While initializing the data, I can access the custom struct at each index without problem.
Once I get outside the initializing loop, suddenly valgrind tells me that I am using an unitialized value of size 8. I really don't understand why this is the case. Using calloc to initialize everything to null did not (as I expected) helped either. Using an array of pointers like FuncSym *f_sym[NB_LINES];
and changing what needed to be changed did not help either. I do think though FuncSym_create(...)
initializes everything correctly.
ANSWER
Answered 2021-Mar-27 at 16:17f_sym[0] was never set because the counter was incremented (++counter
) before entering the if statement. When later accessed f_sym[0] was indeed uninitialized. Fixing counter solved all problems. Just in case anyone ever reads this question.
QUESTION
I've followed the following site instructions in order to implement base64 encoding.
Here's my code:
...ANSWER
Answered 2021-Feb-25 at 03:32According to the site, the task is to convert the hex
to base64
.
Your encoding, seems to be working correctly as the library base64
outputs the same as your result when running it directly over the hex value
QUESTION
Say we declare an array of structs in a local scope:
...ANSWER
Answered 2020-Dec-17 at 00:52Currently the structs in the array are uninitialized
No, they are default-initialized.
While this means that the struct variables are also uninitialized
The effect on the members depends on the definition of RandomStruct
. Depending on that definition, default-initialization of RandomStruct
may have the effect of default-initialization of some or all of the non-static data members of RandomStruct
. It may have the effect eventually of default-initializing a variable of non-class type, as a member of RandomStruct
, or a member of a member, etc. That variable of non-class type will have an indeterminate value.
Like if I, for example, set all the variables from an unitialized struct to the desired value, and then use functions of this struct, or if I use functions of the struct that don't use uninitialized variables before I set them
If all members are initialized to determinate values before being used, everything is OK. Member function calls that don't "observe" the indeterminate values are OK.
Am I correct in thinking that only the variables will be uninitialized and that what the array does is just assign random memory to each of the struct's variables?
That's not quite true. That would imply that observing the indeterminate values is OK but their value is just unknown. It is not. But so long as you don't observe the values, this is a valid intuition.
It is OK to leave them indeterminate so long as they are not observed. But, it is undefined behavior to "observe" the indeterminate value by producing it in any evaluation, except in very limited, enumerated conditions.
This means that a correct program is not allowed to observe the value, but the compiler is also not required to diagnose it. However, the compiler can assume it is never done (because a correct program cannot do it) and C++ places no requirements on an invalid program.
QUESTION
This here is my C++ code:
...ANSWER
Answered 2020-Nov-26 at 14:27The reference documentation for strtok_s
shows that the above code is perfectly valid assuming that string
is not a NULL pointer. Whether "an address of an uninitialized variable is a compile-time constant" is completely irrelevant and doesn't have anything to do with the diagnostic. The compiler thinks you are using uninitialized memory.
However the 4th parameter to strtok_s
, as per documentation, needs to have the pointed-to pointer initialized (by an earlier call to strtok_s
) only if the first parameter is NULL
.
The compiler is being rather picky, it seems. It looks like the compiler cannot prove to itself that string
will never be NULL
here, so it's complaining about this.
But, if you never call strtok_s
here with a NULL
pointer here then there's nothing wrong with this.
QUESTION
I want to use dplyr to calculate a field using it's previous value. A for loop would do the job but I want to calculate by different groups of st. I understand mutate (lag or ave) can't use an unitialized field.
...ANSWER
Answered 2020-Oct-05 at 02:59We can use accumulate
from purrr
to get the output of previous row as an input to current row.
QUESTION
I need to initialize a char array with a loop and print it. Just like that:
...ANSWER
Answered 2020-Sep-07 at 13:15once I declared char array[ 10 ]; does the last subscript contains '\0' ?
No. It's uninitialized. It has garbage values in every element from whatever code used the same piece of memory last.
QUESTION
I've compiled VolPack (https://graphics.stanford.edu/software/volpack/) as a static library in Visual Studio 6 (under Windows XP) because I think that's what it was made for and it wouldn't compile under Visual Studio 2019. But trying to write a C++ program in Visual Studio 2019 and link to volpack.lib I get the error: Error LNK1104 cannot open file 'LIBCD.lib'
(I don't think this is an error specific to VolPack, I think it applies to any lib compiled under VC 6 and then linked to in a later version of VS, so I think the question isn't too specific for StackOverflow.)
I found this: https://support.microsoft.com/en-us/help/154753/description-of-the-default-c-and-c-libraries-that-a-program-will-link, which explains why it's using that lib, but I don't know what to do about it in VS 6. I don't see an option regarding multithreading to change to make it use a different lib, and a quick Google search reveals that VS 6 doesn't support multithreading.
I did find this: How to solve "cannot open file 'LIBCD.lib' " in visual studio 2008?, but I'm not sure the solution is relevant to my issue because the string "GLUI" occurs nowhere in the lib I'm trying to link to. Even if it is the solution to my problem, I don't know where to get the source code for GLUI, exactly what changes I need to make to the makefile, or how to make VS 6 use the new recompiled GLUI, whatever that is.
The next solution was basically to tell the linker to ignore LIBCD.lib, but that gave me other errors. I found this: https://www.youtube.com/watch?v=zKrggjsgQx4, which basically says to ignore LIBCD.lib and then change the runtime library to multi-threaded debug, but that gave me errors too.
The errors I get when trying to compile VolPack under VS 2019 are all "potentially unitialized local pointer variable", so it's probably some simple modifications to get it to compile under VS 2019, but I'm not an expert at C and I don't want to deal with the headache of trying to figure out how to modify the program and of potentially breaking it. So f anybody knows an easy way to solve that problem that might work too. Thanks.
...ANSWER
Answered 2020-Jun-11 at 06:23When you use a static library that has dependencies on other libraries then the compiler is going to complain if it can not find those other libraries.
The difference between Microsoft Visual Studio 6.x and Visual Studio 2019 is immense. As I've ported old code, both C and C++, from 6.x to VS 2015 I have had to make a number of source code changes to allow compiles to work due to the improvements of Microsoft in its adherence to the standards as well as supporting new versions of the standards, some of which deprecate previously supported constructs.
See this post about compatibility between versions, Library ABI compatibility between versions of Visual Studio See as well:
Binary compatibility between VS2017 and VS2015
ABI-Compatibility of visual studio c-libraries
And this blog posting from Microsoft about the release of Visual Studio 2019 dated 2019 says:
Visual Studio 2019 version 16.0 is now available and is binary compatible with VS 2015/2017. In this first release of VS 2019, we’ve implemented more compiler and library features from the C++20 Working Paper, implemented more overloads (C++17’s “final boss”), and fixed many correctness, performance, and throughput issues. Here’s a list of the C++17/20 compiler/library feature work and the library fixes. (As usual, many compiler bugs were also fixed, but they aren’t listed here; compiler fixes tend to be specific to certain arcane code patterns. We recently blogged about compiler optimization and build throughput improvements in VS 2019, and we maintain a documentation page about compiler conformance improvements in VS 2019.)
I don't see any other recourse than to work with the source to make it compatible with Visual Studio 2019. If you look, you may find that your level of expertise with C is sufficient for to implement some of the suggestions below.
The best course of action would seem to be to make the necessary source code changes to the library so that it will compile correctly under Visual Studio 2019.
The best course of action is to review the source code in each place where the uninitialized pointer error is being found and correct the source code so that the error is no longer generated. The programmers who previously worked in those areas of code obviously left out a potential flow of control probably due to their expectation that the missing code would never be executed based on the assumptions of how the function would be used. Most likely any such functions are complex and may need to be refactored.
Most often I have seen this type of missing flow being due to a switch
statement missing a default:
to capture the event of the switch
variable not being one of the specified case values. It may also be due to an if
statement that is a series of else if
without a final else
to capture any other possible condition. Or it may also be due to a loop which has a break
statement before the pointer variable is initialized or which uses a continue
statement to skip where the variable is initialized.
In most cases these issues are due to functions with low cohesion and/or are overly complex and large with maintenance actions over time introducing these kinds of problems.
A less desirable practice for the error of a potentially uninitialized pointer is to just initialize with some appropriate value. You can jump to where the error is, click on the variable and go to where it is defined, and then set it to an appropriate value. In most cases a value of NULL
for pointers is safest because if it stays NULL
and is used without being modified to a correct value, your application should crash letting you know there is a problem.
By initializing to NULL
you are assuming the previous programmers knew what they were doing and the possible flow(s) detected by the compiler that would leave the variable unchanged to a proper value will never happen due to the logic.
And should the uninitialized pointer flow happen, you will find out when the application crashes. Unfortunately tracing back to the origin of the crash may be difficult.
You can use assert
and other tests within the code to create a break point should you be debugging or to generate an exception, if it is C++, which may be more informative than just crashing. So adding such a test just before the line of source code generating the error, checking for NULL
in the test before using the pointer may be helpful.
Or if the function has a status code indicating if it worked or not and any errors along with some way of returning an error status then the most efficient thing would be to use that error reporting at the pointer where the potentially uninitialized pointer error is being generated should the sanity check fail.
However if you can discern a safe default value, you may want to use that instead. Discerning a safe value will require reviewing the source code to determine what the safe default value should be. Sometimes such a safe value can be the address of a variable of the appropriate type initialized to zero.
Warning: if the address in the pointer is being returned, do not use the address of a variable local to the function. When the function returns that address will no longer be valid leading to Undefined Behavior.
Warning 2: if the address in the pointer is expected to have been allocated using malloc()
or new
or similar memory allocator then you must use the same mechanism so that when some code decides to deallocate the memory using free()
or delete
then it will work.
This review will require reading the source code of the function where the uninitialized pointer is being used if the value of the pointer is localized to the function itself. If the pointer is returned by the function, the value exported by the function to a user of the function, then you will also need to review the source code where the function is used in order to determine an appropriate default value.
So what I suggest you do is that every place where you do the initialization, you add a unique identifying comment (something along the lines of "Inhahe fix uninitialized pointer error 06/10/2020") to the line so that you can then do a search to find these at a later time and then go back into the problematic code and actually fix the compiler error by refactoring or changing the code to eliminate the possible uninitialized pointer error.
And before you do anything get the source under version control of some kind.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install Unitial
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