Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 789229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:29:25+00:00 2026-05-14T21:29:25+00:00

Can semantic errors be detected by the compiler or not? If not when do

  • 0

Can semantic errors be detected by the compiler or not? If not when do the errors get detected?

As far as I know semantic errors are those errors which result from the expressions involving operators with incorrect number/type of operands.

For example:

n3=n1*n2;//n1 is integer, n2 is a string, n3 is an integer

The above statement is semantically incorrect.

But while reading C Primer Plus by Stephen Prata I found the following statement

The compiler does not detect semantic errors, because they don’t violate C rules. The compiler has no way of divining your true intentions. That leaves it to you to find these kinds of errors. One way is to compare what a program does to what you expected it to do.

If not the compiler, who detects those errors?

Am I missing something?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T21:29:26+00:00Added an answer on May 14, 2026 at 9:29 pm

    The word “semantic” is ambiguous, and you’ve encountered two slightly different meanings in these different contexts.

    The first meaning (your code) is related to how a compiler interprets the code you type. But there are varying degrees of interpretation for this – syntax is one level, where interpretation is simply deciding that n1*n2 means you want to perform multiplication. But there is also a higher level of interpretation here – if n1 is an integer, and n2 is floating point, what is the result? What if I cast it, should it be rounded, truncated, etc? These are “semantic” questions rather than syntactic ones, but someone, somewhere, decided that yes, the compiler can answer these for most people.

    They also decided that the compiler has limits to what it can (and should!) interpret. For example, it can decide that casting to an int is a truncation, not rounding, but it can’t decide what you really want when you try to multiply an array by a number.

    (Sometimes people decide that they CAN, though. In Python, [1] * 3 == [1,1,1].)

    The second meaning refers to a much wider scope. If the result of that operation is supposed to be sent to a peripheral device that can take values of 0x000 to 0xFFF, and you multiply 0x7FF by 0x010, clearly you’ve made a semantic error. The designers of the peripheral device must decide whether, or how, to cope with that. You, as a programmer, could also decide to put in some sanity checks. But the compiler has no idea about these external semantic constraints, or how to enforce them (filter user input? return an error? truncate? wrap?), which is what the second quote is saying.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 424k
  • Answers 424k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer class Bar: pass class MyUnpickler(pickle.Unpickler): def find_class(self, module, name): if… May 15, 2026 at 12:07 pm
  • Editorial Team
    Editorial Team added an answer You can use a pattern like this: public interface ICommonServices… May 15, 2026 at 12:07 pm
  • Editorial Team
    Editorial Team added an answer There is a demo on the Telerik site that shows… May 15, 2026 at 12:07 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.