2

I am using Xcode 9.4.1 to write a header file in C. For some reason, Xcode always adds a blank line to the end of the file. How can I delete the line in Xcode? Or how do I prevent the extra blank from being generated in Xcode?

#ifndef C2A1E1_MACROS_H
#define C2A1E1_MACROS_H
#define Product(number1, number2) ((number1)*(number2))
#define Negate(number1) (-(number1))
#define Elements(array) ((sizeof(array))/(sizeof((array)[0])))
#endif

Screenshot of original

Screenshot after typing in blank line

Cœur
  • 37,241
  • 25
  • 195
  • 267
Sean Bearden
  • 289
  • 4
  • 14
  • The issue appears to be independent of the code. When I create a new file, then go to the last numbered line, as soon as I type anything in that line Xcode adds a line below it. – Sean Bearden Jul 13 '18 at 04:50
  • This is the rare case where I think a screenshot might help. Maybe two, before and after typing something into the last line without using a newline. – Yunnosch Jul 13 '18 at 04:58
  • @Yunnosch screenshots added. – Sean Bearden Jul 13 '18 at 05:05
  • Pretty clear now - and weird. – Yunnosch Jul 13 '18 at 05:08
  • is that some linting rule? People often want that one empty line but I dont remember the reason. – Sulthan Jul 13 '18 at 05:11
  • No idea. I'm currently taking a C/C++ course online. Our instructor has us submit our files via email, then he has some automatic checker that tests for portability. I keep getting this advisory. (Note that the assignment itself has nothing to do with this issue.) – Sean Bearden Jul 13 '18 at 05:12
  • This question is more suited for superuser site than on stackoverflow. A quick search led me to [this post](https://superuser.com/questions/995082/how-to-force-a-new-line-at-the-end-of-a-file-in-xcode) on superuser which says, it is the default choice for Xcode to include a newline in version 8 and there is no option to disable it. –  Jul 13 '18 at 05:35
  • @kbr I was not sure which would be best. I saw the post you have linked, which did not garner much attention, so I thought I'd try stackoverflow. Some additional information: This is the second course of the program. When I took the first course I used Xcode 8 and never encountered this problem. That being said, I have no idea what the instructor's automatic checker is doing, and it is likely he has modified it since I took the first course. – Sean Bearden Jul 13 '18 at 05:42
  • 1
    Who is showing this advisory now? Is it the compiler that your instructor runs or are you seeing this when you compile your code locally? Or is it some other tool? I use gcc at work and there are thousands of files with a empty line at the end. I haven't seen gcc throwing any warning. If it is your instructor's tool (not compiler), may be you should check with him/her on what is being done. It may be they can fix something at their end. I do not see any merit in throwing a warning for this. –  Jul 13 '18 at 05:54
  • @kbr to be honest I do not know exactly who generates the advisory. The instructor uses many compilers to check for portability, but I believe he adds his own, too. Your comment convinced me it might be a bug on the instructor's end, so I deleted all of the blank lines in the file except the last one. That removed the advisory, so I believe it was an error of the instructor. I'll update the question to remove the part about the advisory. Does the question in and of itself still have merit? Should it be deleted? – Sean Bearden Jul 13 '18 at 06:05
  • 2
    I did some reading of my own and found the exact opposite. Go through [this link](https://stackoverflow.com/questions/72271/no-newline-at-end-of-file-compiler-warning) if you haven't done so already. It is a requirement in C standard to have new lines at the end of the file. You should definitely talk to your instructor about this. I would have the question stay in case anyone comes here for a similar problem and (hopefully) can get redirected to the proper place reading through the comments. Happy coding. –  Jul 13 '18 at 06:18
  • It probably has to do [with not having a newline is undefined behavior](https://stackoverflow.com/a/26127812/1708801) in C++11 the compiler should act as if there is a newline though. – Shafik Yaghmour Jul 13 '18 at 06:59

0 Answers0