Advertisement
Guest User

Untitled

a guest
May 27th, 2017
605
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 3.78 KB | None | 0 0
  1.  
  2. <JoeKiwi> Hi, is there a C channel for amateur c programmers?
  3. <twkm> this one should work.
  4. * PhilSliderS has quit (Ping timeout: 264 seconds)
  5. <vy> We are all amateur...
  6. * posey has quit (Quit: Leaving)
  7. * WoodyWoodpecker (~guy@p549575EA.dip.t-dialin.net) has joined ##c
  8. <JoeKiwi> is this valid C code? : #include <stdio.h> const unsigned int MAX = 10; int array[MAX]; int main(void){ ... }
  9. * buntfalke has quit (Read error: Operation timed out)
  10. * PhilSliderS (~philou@AAmiens-552-1-89-102.w92-155.abo.wanadoo.fr) has joined ##c
  11. <Wulf> I think it's not
  12. <JoeKiwi> i have to use #define instead of const?
  13. * mika_video (~knoppix@cs181066202.pp.htv.fi) has joined ##c
  14. <Wulf> error: variably modified ‘array’ at file scope
  15. * xj has quit (Quit: Leaving...)
  16. <twkm> well, const doesn't make a constant, which is what is needed at file scope.
  17. <vy> JoeKiwi: Using gcc? ıf so compile the code with -std=c89 and -std=c99 options while -Wall is turned on.
  18. <JoeKiwi> oh, im using VS2010
  19. <JoeKiwi> oh ok twkm
  20. <JoeKiwi> confusing, but ok
  21. <twkm> also, as an aside, it is idiomatic that all upper-case identifiers denote macros.
  22. <JoeKiwi> so const unsigned int MAX , should be Max
  23. <Wulf> JoeKiwi: max. lower case.
  24. <JoeKiwi> oh
  25. <twkm> or max or MaX or ...
  26. <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];
  27. <JoeKiwi> I read that using a macro identifier is not type safe
  28. <Wulf> JoeKiwi: macros don't have types.
  29. <JoeKiwi> makes sense then
  30. * kevlolol has quit (Ping timeout: 265 seconds)
  31. * cryolab (~mp@p54B3A141.dip0.t-ipconnect.de) has joined ##c
  32. <ws> that objection doesn't make sense in this context anyway
  33. * diminish (~diminish@nat2-0.elomza.pl) has joined ##c
  34. <JoeKiwi> so they const keyword doesnt make a variable read only file scope?
  35. * kevlolol (~kevin@unaffiliated/kevlolol) has joined ##c
  36. <twkm> read only isn't the same as making a constant.
  37. <JoeKiwi> oh ok, so what IS a constant then?
  38. * buntfalke (~nobody@unaffiliated/buntfalke) has joined ##c
  39. * PhilSliderS has quit (Ping timeout: 264 seconds)
  40. <Seadog> kind of like a promise that you can break if you want
  41. <JoeKiwi> so you can label a variable const, but change the value later on
  42. <twkm> no.
  43. <twkm> you seem to have conflated identifiers with variables.  sadly common when guessing is used to learn c.
  44. <JoeKiwi> hmm
  45. * ts33kr has quit (Ping timeout: 265 seconds)
  46. <JoeKiwi> a little bit harsh there
  47. * nomemory has quit (Ping timeout: 260 seconds)
  48. <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.
  49. <twkm> harsh.  okay, fine ... how are you learning c?  book?  web?  guessing after all?
  50. * h4r1 has quit (Ping timeout: 265 seconds)
  51. * nomemory (~andrei@94-62-140-2.b.ipv4ilink.net) has joined ##c
  52. <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.
  53. * keks_ (~keks@wh163.stw.stud.uni-saarland.de) has joined ##c
  54. <twkm> in c99 a variable can be used to size an array with block scope.
  55. * leibert_ has quit (Read error: Connection reset by peer)
  56. * honschu has quit (Remote host closed the connection)
  57. * MagBo (~Sweater@mpe-2-170.mpe.lv) has joined ##c
  58. * leibert (~leibert@c-66-31-161-155.hsd1.ma.comcast.net) has joined ##c
  59. * inflex has quit (Remote host closed the connection)
  60. * h4r1 (~h4r1@192.73.8.28) has joined ##c
  61. * FatboyPunk has quit (Ping timeout: 265 seconds)
  62. * inflex (~PLD@122-148-188-66.static.dsl.dodo.com.au) has joined ##c
  63. <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
  64. <twkm> *shrug*
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement