Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Comments on Cast uninitialized variable to (void)

Post

Cast uninitialized variable to (void)

+3
−0

Is it undefined behaviour to cast an uninitialized variable to (void)?

Example:

int main()
{
  int x;
  (void)x;
  return 0;
}
History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

2 comment threads

What are you trying to achieve? (3 comments)
I wonder if I should also tag this C++ also. The answer *might* be different for these different lang... (3 comments)
What are you trying to achieve?
Dirk Herrmann‭ wrote over 2 years ago

What is the reason you want to do this, and what would be your intended behavior? It may be possible, but maybe the result / effect is still not what you are hoping for.

Estela‭ wrote over 2 years ago

This is for PLC code. Global variables associated to I/O are defined in a file which is not C code. But they are available for C code. The freestanding C compiler for the PLC deals with that. It is possible to have different configurations in the build environment. And those configurations may include or not some files C files. Which results in some global variables not being used in some configurations. Which results in a warning. And removing that warning is what I wish to achieve. But only for variables known to be used in at least one configuration.

Dirk Herrmann‭ wrote over 2 years ago · edited over 2 years ago

This goes then in a different direction:

  • From a pure C perspective, there is no issue with global variables being uninitialzed. Global variables are always initialized. If you don't given an explicit initializer, they are implicitly initialized to 0.

  • In your case, you are dealing with global variables defined in a different language. This is then not a matter of being classified as undefined or not by the C standard - the standard won't make any statements about such situations at all. It's only a practical question of "does it work" in my setup of languages and tools.