|
Page 1 of 1
|
[ 7 posts ] |
|
Default values in forward declaration
Author |
Message |
Ernest3.14
Professor
Joined: Sat May 18, 2013 1:24 pm Posts: 271 Location: Olympia, WA
|
 Default values in forward declaration
I think this may apply to C in general, but am I allowed to have default values in both the forward declaration and implementation? Because my code compiles if I only declare default values once. My question is, which is best practice? Should I have default values in my header file (forward declaration), or in my implementation (.c file)? And should I specify the default value with comments? Or would that be difficult to maintain? 
_________________FTC Team 6424, the 'Oly Cow - Chief programmer. FRC Team 4450, Olympia Robotics Federation (ORF). and also quadrotors. Quadrotors!
|
Sun Jul 28, 2013 3:41 pm |
|
 |
Ernest3.14
Professor
Joined: Sat May 18, 2013 1:24 pm Posts: 271 Location: Olympia, WA
|
 Re: Default values in forward declaration
Is it good practice to ask about best practices?
_________________FTC Team 6424, the 'Oly Cow - Chief programmer. FRC Team 4450, Olympia Robotics Federation (ORF). and also quadrotors. Quadrotors!
|
Sun Jul 28, 2013 8:19 pm |
|
 |
mightor
Site Admin
Joined: Wed Mar 05, 2008 8:14 am Posts: 3654 Location: Rotterdam, The Netherlands
|
 Re: Default values in forward declaration
Only if you practice first...
In my code I tend to either assign a value (usually 0) to normal types or use memset() to 'zero out' array types. I don't like leaving variables unassigned.
= Xander
_________________| Professional Conduit of Reasonableness| (Title bestowed upon on the 8th day of November, 2013) | My Blog: I'd Rather Be Building Robots| ROBOTC 3rd Party Driver Suite: [ Project Page]
|
Sun Jul 28, 2013 11:53 pm |
|
 |
Ernest3.14
Professor
Joined: Sat May 18, 2013 1:24 pm Posts: 271 Location: Olympia, WA
|
 Re: Default values in forward declaration
Sorry, now I see how that was a really bad question... What I meant was, default values for functions. For example, Currently that would be illegal. Where should I put the `x=15`?
_________________FTC Team 6424, the 'Oly Cow - Chief programmer. FRC Team 4450, Olympia Robotics Federation (ORF). and also quadrotors. Quadrotors!
|
Mon Jul 29, 2013 3:11 pm |
|
 |
mightor
Site Admin
Joined: Wed Mar 05, 2008 8:14 am Posts: 3654 Location: Rotterdam, The Netherlands
|
 Re: Default values in forward declaration
You put it in the prototype only. It makes the argument optional as well. I use this in my suite, quite a bit.
= Xander
_________________| Professional Conduit of Reasonableness| (Title bestowed upon on the 8th day of November, 2013) | My Blog: I'd Rather Be Building Robots| ROBOTC 3rd Party Driver Suite: [ Project Page]
|
Tue Jul 30, 2013 10:54 am |
|
 |
Ernest3.14
Professor
Joined: Sat May 18, 2013 1:24 pm Posts: 271 Location: Olympia, WA
|
 Re: Default values in forward declaration
Ok. Thanks! Should I have the value in comments next to the implementation? Or is that unnecessary?
_________________FTC Team 6424, the 'Oly Cow - Chief programmer. FRC Team 4450, Olympia Robotics Federation (ORF). and also quadrotors. Quadrotors!
|
Tue Jul 30, 2013 3:30 pm |
|
 |
mightor
Site Admin
Joined: Wed Mar 05, 2008 8:14 am Posts: 3654 Location: Rotterdam, The Netherlands
|
 Re: Default values in forward declaration
Only if you think they can't read the code  = Xander
_________________| Professional Conduit of Reasonableness| (Title bestowed upon on the 8th day of November, 2013) | My Blog: I'd Rather Be Building Robots| ROBOTC 3rd Party Driver Suite: [ Project Page]
|
Wed Jul 31, 2013 1:02 am |
|
|
|
Page 1 of 1
|
[ 7 posts ] |
|
Who is online |
Users browsing this forum: No registered users and 2 guests |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|