Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <JoeKiwi> Hi, is there a C channel for amateur c programmers?
- <twkm> this one should work.
- * PhilSliderS has quit (Ping timeout: 264 seconds)
- <vy> We are all amateur...
- * posey has quit (Quit: Leaving)
- * WoodyWoodpecker (~guy@p549575EA.dip.t-dialin.net) has joined ##c
- <JoeKiwi> is this valid C code? : #include <stdio.h> const unsigned int MAX = 10; int array[MAX]; int main(void){ ... }
- * buntfalke has quit (Read error: Operation timed out)
- * PhilSliderS (~philou@AAmiens-552-1-89-102.w92-155.abo.wanadoo.fr) has joined ##c
- <Wulf> I think it's not
- <JoeKiwi> i have to use #define instead of const?
- * mika_video (~knoppix@cs181066202.pp.htv.fi) has joined ##c
- <Wulf> error: variably modified ‘array’ at file scope
- * xj has quit (Quit: Leaving...)
- <twkm> well, const doesn't make a constant, which is what is needed at file scope.
- <vy> JoeKiwi: Using gcc? ıf so compile the code with -std=c89 and -std=c99 options while -Wall is turned on.
- <JoeKiwi> oh, im using VS2010
- <JoeKiwi> oh ok twkm
- <JoeKiwi> confusing, but ok
- <twkm> also, as an aside, it is idiomatic that all upper-case identifiers denote macros.
- <JoeKiwi> so const unsigned int MAX , should be Max
- <Wulf> JoeKiwi: max. lower case.
- <JoeKiwi> oh
- <twkm> or max or MaX or ...
- <twkm> however, if you insist on a non-macro identifer for a constant value use an enum, e.g., enum { max = 10 };, which will work with a file scope int a[max];
- <JoeKiwi> I read that using a macro identifier is not type safe
- <Wulf> JoeKiwi: macros don't have types.
- <JoeKiwi> makes sense then
- * kevlolol has quit (Ping timeout: 265 seconds)
- * cryolab (~mp@p54B3A141.dip0.t-ipconnect.de) has joined ##c
- <ws> that objection doesn't make sense in this context anyway
- * diminish (~diminish@nat2-0.elomza.pl) has joined ##c
- <JoeKiwi> so they const keyword doesnt make a variable read only file scope?
- * kevlolol (~kevin@unaffiliated/kevlolol) has joined ##c
- <twkm> read only isn't the same as making a constant.
- <JoeKiwi> oh ok, so what IS a constant then?
- * buntfalke (~nobody@unaffiliated/buntfalke) has joined ##c
- * PhilSliderS has quit (Ping timeout: 264 seconds)
- <Seadog> kind of like a promise that you can break if you want
- <JoeKiwi> so you can label a variable const, but change the value later on
- <twkm> no.
- <twkm> you seem to have conflated identifiers with variables. sadly common when guessing is used to learn c.
- <JoeKiwi> hmm
- * ts33kr has quit (Ping timeout: 265 seconds)
- <JoeKiwi> a little bit harsh there
- * nomemory has quit (Ping timeout: 260 seconds)
- <twkm> a variable that cannot be changed is not automatically made into a constant, though the compiler is free to treat it as such, but it is not required to do so.
- <twkm> harsh. okay, fine ... how are you learning c? book? web? guessing after all?
- * h4r1 has quit (Ping timeout: 265 seconds)
- * nomemory (~andrei@94-62-140-2.b.ipv4ilink.net) has joined ##c
- <twkm> anyway, an object that is read-only is still an object and might need to be read at run-time, thus cannot provide the compile-time value that sizes an array that is at file scope.
- * keks_ (~keks@wh163.stw.stud.uni-saarland.de) has joined ##c
- <twkm> in c99 a variable can be used to size an array with block scope.
- * leibert_ has quit (Read error: Connection reset by peer)
- * honschu has quit (Remote host closed the connection)
- * MagBo (~Sweater@mpe-2-170.mpe.lv) has joined ##c
- * leibert (~leibert@c-66-31-161-155.hsd1.ma.comcast.net) has joined ##c
- * inflex has quit (Remote host closed the connection)
- * h4r1 (~h4r1@192.73.8.28) has joined ##c
- * FatboyPunk has quit (Ping timeout: 265 seconds)
- * inflex (~PLD@122-148-188-66.static.dsl.dodo.com.au) has joined ##c
- <JoeKiwi> I don't see the correlation of an object not being able to provide a value to to specify an array at compile time if its read-only
- <twkm> *shrug*
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement