Skip to main content
gamedev.net
🔒 Locked

Modifying function parameters

Started by Z01 Jun 1, 2003 at 1:17 AM 0 replies 400+ views
Original Post
Z01
Z01
Is it legal to modify a function parameter in C or C++? I mean things like: int func(int c, char * pString) { c += 2; char * p = "abcdef"; pString = p; return strlen(pString); } I know this compiles and works on MSVC, but is it legal? (works on all compilers and OSes?) I''ve always done this before, it saves having to declare extra local variables sometimes - just use a parameter. Always thought this was legal, but I was talking to another long time coder and he said it makes him nervous and that makes me nervous I don''t want my code to blow up at some future point.
Zipster
Zipster
Absolutely legal. Just make sure you know when the original variable is modified and when it isn't.

[edited by - Zipster on June 1, 2003 2:21:41 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.